Nginx some common configuration

#Define running Nginx users and groups 
#user the nobody; 

#nginx number of processes, recommended setting is equal to the total number of cores CPU. 
. 1 worker_processes; 

# define global error log type, [Debug | info | Notice | The warn | error | Crit] 
#error_log logs / the error.log; 
#error_log logs / Notice the error.log; 
#error_log logs / info the error.log; 

# process file 
# PID logs / nginx.pid; 

# nginx process opens up a number of file descriptors, the theoretical value should be opened up to the number (value of the system ulimit -n) file divided by the number of nginx process, but the allocation request and nginx uneven, it is proposed consistent with the values ulimit -n. 
65535 #worker_rlimit_nofile; 

# operation mode with the maximum number of connections 
Events { 

    # maximum number of connections a single process (the maximum number of connections connecting * = number of processes) 
    worker_connections 65535; 
 
    # reference event model, use [kqueue | rtsig | epoll | / dev / poll | select | poll]; epoll model kernel Linux 2.6 or higher high-performance network I / O model, if run on FreeBSD, use kqueue model.
    #use the epoll; 
} 

# http server set 
{http 
    extension file # file type map 
    include mime.types;

    # Default file type 
    default_type file application / OCTET-Stream; 

    # default encoding 
    #charset-UTF. 8; 

    # server name hash table size 
    #server_names_hash_bucket_size 128; 

    # Upload file size limit 
    #client_header_buffer_size 32K; 

    # reading of a large client request header buffer the maximum size and number of zones 
    #large_client_header_buffers 64K. 4; 

    # nginx can handle this instruction sets the maximum size of the request body. If the request is greater than the specified size, the back nginx HTTP 413 (Request Entity too large) error. # If the server to handle large file uploads, the instruction is very important. 
    8M #client_max_body_size; 
 
    # used to define the format of log (log format can define multiple, different names can be taken)
    #log_format main 'REMOTE_ADDR $ - $ REMOTE_USER [$ time_local] "$ Request"' 
    # '$ $ body_bytes_sent Status "$ HTTP_REFERER"' 
    # ' "$ HTTP_USER_AGENT" "$ HTTP_X_FORWARDED_FOR"';
 
    # is used to specify the path to access the log file using this virtual host and what log format log 
    logs #access_log / the access.log main; 

    # open efficient file transfer mode, nginx sendfile instruction specifies whether the function call sendfile output files for general application to on, if the application used for downloading the disk IO heavy duty applications, may be provided is off, the network to balance the disk I / O processing speed and reduce the load on the system. Note: If the picture is not displayed properly put into this off. 
    ON sendfile; 

    # open access directory listings, download the appropriate server, off by default. 
    ON #autoindex; 

    # prevent network congestion, tcp_nopush configuration and tcp_nodelay "mutually exclusive." It can be configured to send a data packet size. That is, it is not accumulated time after transmitting packet # 0.2 seconds, but when accumulated to a certain size after packet transmission. In the nginx, tcp_nopush must sendfile with use. 
    ON #tcp_nopush; 

    # important to prevent network congestion. . . 
    ON #tcp_nodelay; 

    # longer connection time, in seconds
    0 #keepalive_timeout; 
    keepalive_timeout 120; 


    #FastCGI relevant parameters in order to improve site performance: reducing resource consumption, improve access speed. 

    # Specify a path for the FastCGI cache directory structure level, key regional storage time and inactivity time of deletion.
    #fastcgi_cache_path / usr / local / Nginx / fastcgi_cache Levels. 1 =: 2 = keys_zone the TEST: 5m 10m = inactive; 

    # specified time-out is connected to the rear end of FastCGI. 
    300 #fastcgi_connect_timeout; 

    # FastCGI the transmission request timeout, the timeout value is two-way handshake has been completed after the request to transmit FastCGI. 
    #fastcgi_send_timeout 300; 

    timeout # FastCGI response is received, this value is the time-out has been completed after receiving FastCGI two-way handshake response. 
    300 #fastcgi_read_timeout; 

    # FastCGI specific read a first portion of response needed much buffer 
    #fastcgi_buffer_size 64K; 

    # specify how many and what the local buffer used to buffer FastCGI response 
    #fastcgi_buffers 64K. 4; 

    # default is two fastcgi_buffers times. 
    #fastcgi_busy_buffers_size 128k;

    # How hard the data block when writing fastcgi_temp_path 
    #fastcgi_temp_file_write_size 128K; 

    #gzip module disposed
 
    # gzip compression output opening
    ON #gzip; 

    # minimum compressed file size 
    #gzip_min_length 1K; 

    # decompression buffer 
    #gzip_buffers 16K. 4; 

    # compressed version (1.1 default, if the distal end use squid2.5 1.0) 
    #gzip_http_version 1.0; 

    # compression level 
    #gzip_comp_level 2; 

    # compression type, default already included textml, so the following do not need to write, and write up there will not be a problem, but there will be a warn. 
    text #gzip_types / Plain file application / X-JavaScript text / CSS file application / XML; 

    # Gzip function is provided with a transmission with a "Vary: Accept-Encoding" header field of the response header 
    #gzip_vary ON; 

    # turn limits the number of IP connections the need to use 
    #limit_zone binary_remote_addr crawler $ 10m; 

    #upstream load balancing, weight is the weight that can be configured according to the definition of the weight machine. The higher the greater the chance weigth parameter is the weight, the weight value is assigned to. 
    Upstream coreqi.cn {# 
    # =. 3 Server 192.168.80.121:80 weight;
    Server 192.168.80.122:80 weight = 2 #; 
    # = weight 192.168.80.123:80 Server. 3; 
    #} 

    # Virtual Host Configuration 
    Server { 

        # listening port 
        the listen 80; 

        # can have multiple domain names, separated by spaces 
        server_name localhost ; 

        # should be set up home 
        #index index.html index.htm index.php; 

        root directory # specified item 
        # root / the Data / the WWW / ha97; 

        # php configuration settings 
        # location ~ * (php | php5 )..? $ 
        # { 
        # fastcgi_pass 127.0.0.1:9000; 
        # fastcgi_index the index.php; 
        # the include fastcgi.conf; 
        #} 

        # image cache time
        .. # LOCATION ~ * (GIF | JPG | jpeg | PNG | BMP | SWF) $ 
        # { 
        # the Expires 10d; 
        #} 

        #js CSS caching and time settings 
        .. # LOCATION ~ * (JS | CSS) $? 
        # { 
        Expires IH #; 
        #} 


        # is used to define the format of log (log format can define multiple, different names can take) 
        # log_format Access' REMOTE_ADDR $ - $ REMOTE_USER [$ time_local] "$ Request" ' 

        #' $ Status body_bytes_sent $ "$ HTTP_REFERER" ' 

        #' "$ HTTP_USER_AGENT" $ HTTP_X_FORWARDED_FOR '; 

        # default encoding 
        #charset KOI8-R & lt; 

        # specifies this virtual host access path to the log file and log log format which uses 
        #access_log logs /host.access.log main;

        # On the "/" enable reverse proxy (case a) 
        LOCATION / { 
            the root HTML; 
            index index.html index.htm; 
        } 
        
        # on the "/" enable reverse proxy (Case II) 
        LOCATION / { 

        # Configure forwarding agent, if url behind proxy_pass plus / indicates the root of the absolute path; without /, represents a relative path, the path portion also matched to the agent away. 
        http://127.0.0.1:88 proxy_pass; 

        #Nginx do reverse proxy, if the header is set Host parameters, and when there is an agreement and if there are inconsistencies secondary directory, and 
        # 302, 301 when the back-end services to do Location jump when needed proxy_redirect provided in response header to the back-end of doing the conversion. 
        proxy_redirect OFF; 

        # 
        proxy_set_header the X-real-IP-$ REMOTE_ADDR; 

        # back-end Web server can get the user's real IP by X-Forwarded-For 
        proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for ;

        # Here are some reverse proxy configuration, optional. 
        # 
        Proxy_set_header the Host Host $; 

        # allows clients to request a maximum number of bytes single file 
        client_max_body_size 10m; 

        # buffering agent buffers the maximum number of bytes requested by the client, 
        client_body_buffer_size 128K; 

        #nginx connection time with a backend server (proxy connection timeout) 
        proxy_connect_timeout 90; 

        # backend server data return time (send timeout) 
        proxy_send_timeout 90; 

        # after successful connection, the response time of the back-end server (proxy receive timeout) 
        proxy_read_timeout 90; 

        # proxy settings (Nginx) to save the user header information buffer size 
        proxy_buffer_size 4K; 

        #proxy_buffers buffer, page 32k is disposed below the average 
        proxy_buffers 32k. 4; 

        # buffer size under a high load (proxy_buffers * 2) 
        proxy_busy_buffers_size 64K;

        # Set cache folder size greater than this value, from the upstream server transfer 
        proxy_temp_file_write_size 64K; 
        } 

        # Check Nginx state setting address 
        LOCATION / NginxStatus { 
        stub_status ON; 
        access_log ON; 
        auth_basic "NginxStatus"; 
        auth_basic_user_file confpasswd; 
        #htpasswd file the content can be provided apache htpasswd tool to generate. 
        } 

        # Local static and dynamic separation reverse proxy configuration 
        # all jsp pages were handed over to tomcat or resin treatment 
        LOCATION ~ (jsp | jspx | do) {$.? 
        Proxy_set_header $ Host Host; 
        proxy_set_header the X-Real-IP-$ REMOTE_ADDR; 
        proxy_set_header the X- $ proxy_add_x_forwarded_for the For--Forwarded; 
        proxy_pass http://127.0.0.1:8080;
        } 
        # PHP script will Apache proxy to listen for 127.0.0.1:80

        # All static files are read by nginx or directly without tomcat Resin 
        LOCATION ~ * (HTM |.. HTML | GIF | JPG | jpeg | PNG | BMP | SWF | IOC | RAR | ZIP | TXT | FLV | MID | DOC | PPT | pdf | XLS | MP3 | WMA) $ { 
        the Expires 15d; 
        } 
        
        ..? LOCATION ~ * (JS | CSS) $ { 
        the Expires 1H; 
        } 

        # error page configuration 
        #error_page 404 /404.html; 

        # server error page redirect to a static page /50x.html 
        # 
        error_page 500 502 503 504 /50x.html; 
        LOCATION = {/50x.html 
            the root HTML; 
        } 

        # the Proxy the PHP scripts to the Apache Listening ON 127.0.0.1:80 
        #location ~ \. {$ PHP 
        proxy_pass of http://127.0.0.1 #; 
        #} 

        # Pass at The PHP scripts to FastCGI Server Listening ON 127.0.0.1:9000 
        # php script will be passed to the fastcgi server, listening 127.0.0.1:9000 
        # location ~ \ .php $ { 
        # HTML root; 
        # fastcgi_pass 127.0.0.1:9000; 
        # fastcgi_index index.php; 
        # fastcgi_param SCRIPT_FILENAME / scripts $ fastcgi_script_name; 
        # the include fastcgi_params; 
        #} 

        # .htaccess deny Access to Files, IF the Apache's the Document root 
        # nginx's One concurs with 
        # if apache document root according to the document root directory nginx is denied access to the .htaccess file 
        # location /\.ht ~ { 
        # All deny;
        } # 
    } 


    # Another Mix of the using Virtual IP-Host, name-, and Port-based Configuration 
    # another virtual host configuration based IP, name and port combination 
    #server { 
    # the listen 8000; 
    # the listen somename: 8080; 
    Alias another.alias server_name somename #; 

    # LOCATION / { 
    # the root HTML; 
    # index index.html index.htm; 
    #} 
    #} 


    # the HTTPS server 
    # the HTTPS server 
    #server { 
    # the listen SSL 443; 
    # server_name localhost; 

    # ssl_certificate CERT .pem; 
    # ssl_certificate_key cert.key;
 
    # ssl_session_cache Shared: SSL: 1M;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

Guess you like

Origin www.cnblogs.com/fanqisoft/p/11244860.html