docker 에서 nginx 로 그 를 사용자 정의 하고 ip 접근 을 제한 합 니 다.

2295 단어 nginx
1. Nginx 배치
docker-compose.yml
version: '2'
services:
     nginx:
      image: 'nginx:latest'
      restart: always
      container_name: nginx
      ports:
        - '80:80'
        - '443:443'
      volumes:
        - '/app/nginx/conf.d:/etc/nginx/conf.d'
        - '/app/nginx/logs:/etc/nginx/logs'
      command:  nginx -g 'daemon off;'

디 렉 터 리 생 성:
mkdir -p /app/nginx/logs mkdir -p /app/nginx/conf.d
conf. d / default. conf 설정 파일
server {
    listen       80;
    server_name localhost;
    #       ,log    main(  )
    access_log logs/access_service.log main; 
   location / {
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_pass http://xxx.com;
       client_max_body_size    100m;
      }

     error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

2. IP 접근 제한
1. 방문 자 ip 찾기 방법: awk '{print $1}' accessservice.log |sort |uniq -c|sort -n
2. 설정 파일 conf. d / default. conf
server {
    listen       80;
    server_name localhost;
    access_log  logs/access_service.log  main; 
     #    ip  server  
      deny 172.20.0.1; 
   location / {
      #    ip  location  
      # deny 172.20.0.1; 
      allow 172.20.0.1;

       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_pass http://test.xylink.cn;
       client_max_body_size    100m;
      }
     error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

ip 문법 제한: deny 와 allow 는 http, server, location 단계 에 적용 할 수 있 습 니 다.
//    ip  
deny IP; 
//    ip  
allow IP; 
//    ip  
deny all; 
//    ip  
allow all; 
//       123.0.0.1 123.255.255.254     
deny 123.0.0.0/8
//  IP   123.45.0.1 123.45.255.254     
deny 124.45.0.0/16
//  IP   123.45.6.1 123.45.6.254     
deny 123.45.6.0/24
//           ,    IP ,      ,
//     guolv_ip.conf    
allow 1.1.1.1; 
allow 1.1.1.2;
deny all; 

좋은 웹페이지 즐겨찾기