nginx 제품 환경 보안 설정 - 주 프로필

3010 단어
다음 설정 은 제품 환경 을 위 한 nginx 보안 과 효율 을 기반 으로 하 는 메 인 프로필 입 니 다. fastcgi 관련 설정 은 포함 되 지 않 습 니 다.
cat /etc/nginx/nginx.conf
user                   nginx;
worker_processes       auto;
error_log              /var/log/nginx/error.log;
pid                    /run/nginx.pid;
include                /usr/share/nginx/modules/*.conf;
events {
    use                epoll;
    multi_accept       on;
    worker_connections 2048;
}
http {
   #       
    ## 1.      
    server_tokens       off;
    ## 2.      fram/iframe/object  ,    
    add_header          X-Frame-Options SAMEORIGIN;
    ## 3.        ,        
    add_header          X-Content-Type-Options nosniff;
    ## 4.  XSS  ,    XSS  ,      
    add_header          X-XSS-Protection "1; mode=block";
   #              
    include             /etc/nginx/conf.d/*.conf; 
    include             mime.types;
    default_type        application/octet-stream;
   # sendfile tcp    
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
   #   gzip  
    gzip                on; 
    gzip_min_length     5k;
    gzip_buffers        4 16k;
    gzip_comp_level     2;
    gzip_vary           on;
   #            
    client_max_body_size        100m;
    client_body_buffer_size     8K;
    client_header_buffer_size   64k; 
    large_client_header_buffers 4 128k;
   #  DDOS    
    ## 2.  IP      50   
    limit_conn_zone $binary_remote_addr zone=TCLZone:20m ;
    limit_conn_log_level notice;
    limit_conn  TCLZone  50;
    ## 3.  IP      10   ,5   
    limit_req_zone $binary_remote_addr  zone=CLZone:20m rate=10r/s;
    limit_req_log_level notice;
    limit_req zone=CLZone burst=5 nodelay;
   #          ,     json  ,       
    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    log_format main_json '{"@timestamp":"$time_local",'
                         '"N_client_ip": "$remote_addr",'
                         '"N_request": "$request",'
                         '"N_request_time": "$request_time",'
                         '"N_status": "$status",'
                         '"N_bytes": "$body_bytes_sent",'
                         '"N_user_agent": "$http_user_agent",'
                         '"N_x_forwarded": "$http_x_forwarded_for",'
                         '"N_referer": "$http_referer"'
                         '}';
    access_log  /var/log/nginx/access.log  main_json;
   #     IP  ,        
    server {
        listen 80;
        server_name - ;
        return 501;
    }
}

좋은 웹페이지 즐겨찾기