Nginx - 프로필 상세 설명

20354 단어 Nginx
#   nginx          
user www www;

#nginx    ,        CPU     。
worker_processes 8;

#nginx            CPU,      worker_cpu_affinity             CPU 
#    8       
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

#          ,[ debug | info | notice | warn | error | crit ]
error_log /var/log/nginx/error.log info;

#    
pid /var/run/nginx.pid;

#   nginx               ,             (     ulimit -n)
#  nginx      ,   nginx         ,      ulimit -n       。
worker_rlimit_nofile 65535;

#          
events
{
    #      ,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll     Linux 2.6 
    #              I/O   ,     FreeBSD   ,   kqueue   。
    #epoll       IO(I/O Multiplexing)       ,      linux2.6     ,       nginx    
    use epoll;

    ############################################################################
    #     worker process           
    #      ,   nginx          ,   1024。         worker_processes   worker_connections   
    #  max_client=worker_processes*worker_connections,         :max_client=worker_processes*worker_connections / 4
    worker_connections 65535;
    ############################################################################
}

#   http    
http {
    include mime.types; #             
    default_type application/octet-stream; #      
    #charset utf-8; #    

    server_names_hash_bucket_size 128; #       hash    
    client_header_buffer_size 32k; #        
    large_client_header_buffers 4 64k; #     
    client_max_body_size 8m; #     
    sendfile on; #          ,sendfile      nginx      sendfile        ,         on,              IO      ,     off,         I/O     ,       。  :               off。
    autoindex on; #        ,       ,    。
    tcp_nopush on; #      
    tcp_nodelay on; #      

    ##               ##
    keepalive_timeout  120;          #    ,        ,                   nginx              ,            http   ,      http   
    client_header_timeout 10;        #           
    client_body_timeout 10;          #           
    reset_timedout_connection on;    #   nginx            。                  
    send_timeout 10;                 #         ,            。        ,           ,nginx       
    ################################

    #FastCGI               :      ,      。             。
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    ###           #######
    ###    temp      cache
    #proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zone=cache_one:512m inactive=10m max_size=64m;
    ###   proxy_temp   proxy_cache          
    ###levels=1:2       ,              1    ,       2     keys_zone=cache_one:128m         cache_one     512m
    ###max_size=64m          128m        inactive=10m        ,10             
    #########end####################

    #####       ###########
    #gzip     
    gzip on; #   gzip     
    gzip_min_length 1k; #        
    gzip_buffers 4 16k; #     
    gzip_http_version 1.0; #    (   1.1,      squid2.5     1.0)
    gzip_comp_level 2; #    ,gzip    ,1    ,    ;9       ,    ,      ,     CPU;
    gzip_types text/plain application/x-javascript text/css application/xml;
    #    ,        text/html,          ,         ,       warn。
    gzip_vary on;
    ##############################

    #limit_zone crawler $binary_remote_addr 10m; #     IP           

    upstream blog.ha97.com {
        #upstream      ,weight    ,            。weigth       ,             。
        server 192.168.80.121:80 weight=3;
        server 192.168.80.122:80 weight=2;
        server 192.168.80.123:80 weight=3;
    }

    #       
    server {
        #    
        listen 80;

        #############https##################
        #listen 443 ssl;
        #ssl_certificate /opt/https/xxxxxx.crt;
        #ssl_certificate_key /opt/https/xxxxxx.key;
        #ssl_protocols SSLv3 TLSv1;
        #ssl_ciphers HIGH:!ADH:!EXPORT57:RC4+RSA:+MEDIUM;
        #ssl_prefer_server_ciphers on;
        #ssl_session_cache shared:SSL:2m;
        #ssl_session_timeout 5m;
        ####################################end

        #       ,     
        server_name www.ha97.com ha97.com;
        index index.html index.htm index.php;
        root /data/www/ha97;
        location ~ .*.(php|php5)?$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

        #        
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
            expires 10d;
        }

        #JS   CSS       
        location ~ .*.(js|css)?$ {
            expires 1h;
        }

        #      
        log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for';

        #            
        access_log /var/log/nginx/ha97access.log access;

        #  "/"       
        location / {
            proxy_pass http://127.0.0.1:88;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            #    Web         X-Forwarded-For        IP
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #            ,  。
            proxy_set_header Host $host;
            client_max_body_size 10m; #                
            client_body_buffer_size 128k; #                  ,

            ##           nginx              ##
            proxy_connect_timeout 90; #nginx             (      )
            proxy_send_timeout 90; #           (      )
            proxy_read_timeout 90; #     ,         (      )
            proxy_buffering on;    #                             proxy_buffers   proxy_busy_buffers_size        
            proxy_buffer_size 4k;  #       (nginx)             
            proxy_buffers 4 32k;   #proxy_buffers    ,      32k      
            proxy_busy_buffers_size 64k; #        (proxy_buffers*2)
            proxy_max_temp_file_size 2048m; #   1024m,                proxy_buffers  ,          。         ,    upstream           ,        
            proxy_temp_file_write_size 512k;                 nginx              。
            proxy_temp_path  /var/tmp/nginx/proxy_temp;    ##        ,             
            proxy_headers_hash_max_size 51200;
            proxy_headers_hash_bucket_size 6400;
            #######################################################
        }

        #     nginx      
        location /nginxStatus {
            stub_status on;
            access_log on;
            auth_basic "nginxStatus";
            auth_basic_user_file conf/htpasswd;
            #htpasswd          apache     htpasswd      。
        }

        #            
        #   jsp        tomcat   resin   
        location ~ .(jsp|jspx|do)?$ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080;
        }

        #        nginx         tomcat   resin
        location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
        { expires 15d; }

        location ~ .*.(js|css)?$
        { expires 1h; }
    }
}

좋은 웹페이지 즐겨찾기