(Summary) nginx configuration file nginx. conf Chinese explanation (from: http://www.ha97.com/5194.html)

Source: Internet
Author: User
Tags sendfile website performance

PS: I have been using nginx for two or three years. Now I often encounter some basic questions from new users. I have no time to answer them one by one. It took me some time this afternoon, based on your experience, I will share the main configuration parameters of nginx and some network content. This is the most complete Chinese description of nginx configuration parameters. For more detailed module parameters, see: http://wiki.nginx.org/Main


# Define users and user groups for running nginx
User WWW;

# Number of nginx processes. We recommend that you set it to equal to the total number of CPU cores.
Worker_processes 8;

# Global Error Log definition type, [debug | info | notice | warn | error | crit]
Error_log/var/log/nginx/error. Log Info;

# Process files
Pid/var/run/nginx. PID;

# The maximum number of file descriptors opened by an nginx process. The theoretical value should be that the maximum number of opened files (system value ulimit-N) is the same as the number of nginx processes, but the allocation requests of nginx are uneven, therefore, we recommend that you keep the value consistent with that of ulimit-n.
Worker_rlimit_nofile 65535;

# Maximum number of working modes and connections
Events
{
# Refer to the event model. Use [kqueue | rtsig | epoll |/dev/poll | select | poll]. The epoll model is a high-performance network I/O model in the kernel of Linux 2.6 or later versions, if you run on FreeBSD, use the kqueue model.
Use epoll;
# Maximum number of connections of a single process (maximum number of connections = number of connections * Number of processes)
Worker_connections 65535;
}

# Set the HTTP server
HTTP
{
Include mime. types; # file extension and file type ing table
Default_type application/octet-stream; # default file type
# Charset UTF-8; # default encoding
Server_names_hash_bucket_size 128; # size of the hash table with the server name
Client_header_buffer_size 32 K; # size limit of uploaded files
Large_client_header_buffers 4 64 K; # Set Request latency
Client_max_body_size 8 m; # Set Request Delay
Sendfile on; # enable the efficient file transmission mode. The sendfile command specifies whether nginx calls the sendfile function to output files. For common applications, set it to on, if it is used for application disk I/O heavy load applications such as downloading, you can set it to off to balance the disk and network I/O processing speed and reduce the system load. Note: If the image is not displayed properly, change it to off.
Autoindex on; # enable directory list access, which is suitable for downloading servers. It is disabled by default.
Tcp_nopush on; # prevent network congestion
Tcp_nodelay on; # prevent network congestion
Keepalive_timeout 120; # long connection timeout time, in seconds

# FastCGI parameters are used to improve website performance: reduce resource usage and increase access speed. The following parameters can be understood literally.
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64 K;
Fastcgi_buffers 4 64 K;
Fastcgi_busy_buffers_size 128 K;
Fastcgi_temp_file_write_size 128 K;

# Gzip Module Settings
Gzip on; # enable gzip compression output
Gzip_min_length 1 K; # minimum compressed file size
Gzip_buffers 4 16 K; # compression Buffer
Gzip_http_version 1.0; # compression version (1.1 by default. Use 1.0 if squid2.5 is the frontend)
Gzip_comp_level 2; # compression level
Gzip_types text/plain application/X-JavaScript text/CSS application/XML;
# Compression type. Text/html is already included by default, so you don't need to write any more below. There will be no problem in writing, but there will be a warn.
Gzip_vary on;
# Limit_zone crawler $ binary_remote_addr 10 m; # use this function when you enable the IP address connection restriction.

Upstream blog.ha97.com {
# Upstream Server Load balancer. weight is the weight. You can define the weight according to the machine configuration. The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
Server 192.168.80.121: 80 Weight = 3;
Server 192.168.80.122: 80 Weight = 2;
Server 192.168.80.123: 80 Weight = 3;
}

# VM Configuration
Server
{
# Listening port
Listen 80;
# Multiple domain names can be separated by Spaces
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;
}
# Image cache time settings
Location ~ . *. (GIF | JPG | JPEG | PNG | BMP | SWF) $
{
Expires 10d;
}
# JS and CSS cache time settings
Location ~ . *. (JS | CSS )? $
{
Expires 1 h;
}
# Log format settings
Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
# Define access logs for the current virtual host
Access_log/var/log/nginx/ha97access. Log Access;

# Enable reverse proxy "/"
Location /{
Proxy_pass http: // 127.0.0.1: 88;
Proxy_redirect off;
Proxy_set_header X-real-IP $ remote_addr;
# The backend web server can use X-forwarded-for to obtain the user's real IP address.
Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
# The following are some reverse proxy configurations, which are optional.
Proxy_set_header host $ host;
Client_max_body_size 10 m; # maximum number of bytes allowed for client requests per file
Client_body_buffer_size 128 K; # maximum number of bytes for the buffer proxy to buffer client requests,
Proxy_connect_timeout 90; # timeout for nginx connection to backend servers (proxy connection timeout)
Proxy_send_timeout 90; # backend server data return time (proxy sending timeout)
Proxy_read_timeout 90; # response time of the backend server after successful connection (proxy receiving timeout)
Proxy_buffer_size 4 K; # Set the buffer size for the proxy server (nginx) to save user header information
Proxy_buffers 4 32 K; # proxy_buffers buffer, the average web page is less than 32 K settings
Proxy_busy_buffers_size 64 K; # buffer size under high load (proxy_buffers * 2)
Proxy_temp_file_write_size 64 K;
# Set the cache folder size. If it is greater than this value, it will be uploaded from the upstream Server
}

# Set the address for viewing nginx status
Location/nginxstatus {
Stub_status on;
Access_log on;
Auth_basic "nginxstatus ";
Auth_basic_user_file CONF/htpasswd;
# The content of the htpasswd file can be generated using the htpasswd tool provided by Apache.
}

# Reverse proxy configuration for local dynamic/static Separation
# All JSP pages are processed by tomcat or 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;
}
# All static files are directly read by nginx without passing through tomcat or 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 1 h ;}
}
}

For more detailed module parameters, see: http://wiki.nginx.org/Main

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.