Nginx configuration details _ Nginx configuration file nginx. conf

Source: Internet
Author: User
Tags epoll sendfile website performance
The main configuration parameters of Nginx are described and some network content is also referenced. This is the most complete description of Nginx configuration parameters in Chinese. # 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 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

Related Article

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.