Nginx conf configuration details
During Nginx configuration, there will be many things you don't understand. In fact, sometimes you only need to change your mind to find more ways to solve the problem. Official configuration example: http://wiki.nginx.org/NginxFullExample
# Run the user nobody; # Start the worker_processes process 4; # global error log and PID documentation [debug | info | notice | warn | error | crit] error_log logs/error. log notice; pid logs/Nginx. pid; # working mode and maximum number of connections events {# Working Mode: # use [kqueue | rtsig | epoll |/dev/poll | select | poll]; use epoll; worker_connections 1024;} # sets the http server and uses its reverse proxy function to provide Load Balancing support for http {# sets the mime type include conf/mime. types; default_type application/octet-st Ream; # Set the log format log_format main' $ remote_addr-$ remote_user [$ time_local] ''" $ request "$ status $ bytes_sent'' "$ http_referer" "$ http_user_agent" ''" $ gzip_ratio "'; log_format download '$ remote_addr-$ remote_user [$ time_local] ''" $ request "$ status $ bytes_sent'' "$ http_referer" "$ http_user_agent" ''" $ http_range "$ sent_http_content_range "'; # Set the Request Buffer client_header_buffer_size 1 k; large_client_head Er_buffers 4 4 k; # enable gzip module gzip on; gzip_min_length 1100; gzip_buffers 4 8 k; gzip_types text/plain; output_buffers 1 32 k; postpone_output 1460; # Set access log access_log logs/access. log main; client_header_timeout 3 m; client_body_timeout 3 m; send_timeout 3 m; sendfile on; # Use of sendfile () activated or disabled by the command. Tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; # Set the Server list of Server Load balancer upstream mysvr {# The weigth parameter indicates the weight value, the higher the weight, the higher the chance of being allocated to it # enable port 3128 of server 192.168.8.1: 3128 weight = 5 on Squid on the local machine; server 192.168.8.2: 80 weight = 1; server 192.168.8.3: 80 weight = 6 ;}# set the virtual host server {listen 80; server_name 192.168.8.1 www.yejr.com; charset utf8; # Set the access log access_log logs/www.yejr.com of the virtual host. access. log main; # If you access/img/*,/js/*,/css /* If you do not use squid # if there are many documents, this method is not recommended because the squid cache works better ~ ^/(Img | js | css)/{root/data3/Html; expires 24 h;} # enable Server Load balancer location/{proxy_pass http://mysvr ; Proxy_redirect off; proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ scheme; limit 10 m; Limit 128 k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4 k; proxy_buffers 4 32 k; Limit 64 k; Limit 64 k;} # Set the address location/NginxStatus {stub_status on for viewing Nginx status; access_log on; auth_basic "NginxStatus"; auth_basic_user_file conf/htpasswd ;}# error_page 404/404 .html; # location/404.html {# root/spool/www; # charset on; # source_charset koi8-r; #}# location/old_stuff/{# rewrite ^/old_stuff /(. *) $/new_stuff/$1 permanent; #}# location/download/{# valid_referers none blocked server_names * .example.com; # if ($ invalid_referer) {## rewrite ^/ http://www.example.com/ ; # Return 403; #}# rewrite_log on; ## rewrite/download/*/mp3 /*. any_ext to/download/*/mp3 /*. mp3 # rewrite ^/(download /. *)/mp3 /(. *)\.. * $/$1/mp3/ipv2.mp3 break; # root/spool/www; # autoindex on; # access_log/var/log/nginx-download.access_log download; #}# location ~ * ^. + \. (Jpg | jpeg | gif) $ {# root/spool/www; # access_log off; # expires 30d ;#}}}
Note: The content of conf/htpasswd is generated using the htpasswd tool provided by apache.
View Nginx running status input address http: // 192.168.8.1/NginxStatus /. Enter the verification account password and you will see something similar to the following:
Active connections: 328 server accepts handled requests 9309 8982 28890 Reading: 1 Writing: 3 Waiting: 324
The first line indicates the number of active connections, and the third number in the third line indicates that Nginx is running.