Nginx standard configuration file

Source: Internet
Author: User
# Nginx. conf # run userwww-data; # start the process. Generally, the number of worker_processes1 is set to equal to the number of CPUs. # the global error log and the PID file error_log/var/log/nginx/error. log; pid/var/run/nginx. pid; # working mode...

 

# Nginx. conf

 

# Running user

User www-data;

# Start the process. generally, it is set to be equal to the number of CPUs

Worker_processes 1;

 

# Global error logs and PID files

Error_log/var/log/nginx/error. log;

Pid/var/run/nginx. pid;

 

# Working mode and maximum number of connections

Events {

Use epoll; # epoll is a method of Multiplexing IO (I/O Multiplexing), but it is only used for Linux and later kernels, which can greatly improve nginx performance.

Worker_connections 1024; # maximum number of concurrent connections of a single backend worker process

# Multi_accept on;

}

 

# Set the http server and use its reverse proxy function to provide load balancing support

Http {

# Set the mime type, which is defined by the mime. type file.

Include/etc/nginx/mime. types;

Default_type application/octet-stream;

# Set the log format

Access_log/var/log/nginx/access. log;

 

# The sendfile command specifies whether nginx calls the sendfile function (zero copy mode) to output files. for common applications,

# It must be set to on. if it is used for downloading and other application disk I/O heavy load applications, you can set it to off to balance the disk and network I/O processing speed and reduce the system uptime.

Sendfile on;

# Tcp_nopush on;

 

# Connection timeout

# Keepalive_timeout 0;

Keepalive_timeout 65;

Tcp_nodelay on;

 

# Enable gzip compression

Gzip on;

Gzip_disable "MSIE [1-6] \. (?!. * SV1 )";

 

# Set request buffer

Client_header_buffer_size 1 k;

Large_client_header_buffers 4 4 k;

 

Include/etc/nginx/conf. d/*. conf;

Include/etc/nginx/sites-enabled /*;

 

# Set the server list of server load balancer

# The backend Web server can use X-Forwarded-For to obtain the user's real IP address.

Proxy_set_header Host $ host;

Proxy_set_header X-Real-IP $ remote_addr;

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

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, if the average web page is below 32 k, this setting

Proxy_busy_buffers_size 64 k; # buffer size under high load (proxy_buffers * 2)

Proxy_temp_file_write_size 64 k; # sets the cache folder size. if it is greater than this value, it will be transmitted from the upstream server

 

}

 

}

}

 

 

}

 

# Define error prompt page

Error_page 500 502 503 x.html;

Location =/50x.html {

Root/root;

}

 

# Handle static files by nginx

Location ~ ^/(Images | javascript | js | css | flash | media | static )/{

Root/var/www/virtual/htdocs;

# Static files are not updated for 30 days after they expire. you can set them to a larger value when they expire. if they are updated frequently, you can set them to a smaller value.

Expires 30d;

}

# PHP script requests are all forwarded to FastCGI for processing. use the default FastCGI configuration.

Location ~ \. Php $ {

Root/root;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME/home/www $ fastcgi_script_name;

Include fastcgi_params;

}

# Set the address for viewing Nginx status

Location/NginxStatus {

Stub_status on;

Access_log on;

Auth_basic "NginxStatus ";

Auth_basic_user_file conf/htpasswd;

}

# Prohibit access to the. htxxx file

Location ~ /\. Ht {

Deny all;

}

}

}

Upstream mysvr {

# The weigth parameter indicates the weight. a higher weight indicates a higher probability of being assigned.

# Enable port 3128 for Squid on the local machine

Server 192.168.8.1: 3128 weight = 5;

Server 192.168.8.2: 80 weight = 1;

 

Server 192.168.8.3: 80 weight = 6;

}

 

Upstream mysvr2 {

# The weigth parameter indicates the weight. a higher weight indicates a higher probability of being assigned.

 

Server 192.168.8.x: 80 weight = 1;

Server 192.168.8.x: 80 weight = 6;

}

 

Server {

 

# Listening to port 80

Listen 80;

# Define access using www.xx.com

Server_name www.xx.com;

 

# Set access logs for the current virtual host

Access_log logs/www.xx.com. access. log main;

 

# Default request

Location /{

Root/root; # define the default website root directory location of the server

Index. php index.html index.htm; # define the name of the home index file

 

Proxy_pass http: // mysvr; # Redirect requests to the list of servers defined by mysvr

 

# The following are some reverse proxy configurations that can be deleted.

 

Proxy_redirect off;

 

# The backend Web server can use X-Forwarded-For to obtain the user's real IP address.

Proxy_set_header Host $ host;

Proxy_set_header X-Real-IP $ remote_addr;

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

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, if the average web page is below 32 k, this setting

Proxy_busy_buffers_size 64 k; # buffer size under high load (proxy_buffers * 2)

Proxy_temp_file_write_size 64 k; # sets the cache folder size. if it is greater than this value, it will be transmitted from the upstream server

 

}

 

}

}

 

 

}

 

# Define error prompt page

Error_page 500 502 503 x.html;

Location =/50x.html {

Root/root;

}

 

# Handle static files by nginx

Location ~ ^/(Images | javascript | js | css | flash | media | static )/{

Root/var/www/virtual/htdocs;

# Static files are not updated for 30 days after they expire. you can set them to a larger value when they expire. if they are updated frequently, you can set them to a smaller value.

Expires 30d;

}

# PHP script requests are all forwarded to FastCGI for processing. use the default FastCGI configuration.

Location ~ \. Php $ {

Root/root;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME/home/www $ fastcgi_script_name;

Include fastcgi_params;

}

# Set the address for viewing Nginx status

Location/NginxStatus {

Stub_status on;

Access_log on;

Auth_basic "NginxStatus ";

Auth_basic_user_file conf/htpasswd;

}

# Prohibit access to the. htxxx file

Location ~ /\. Ht {

Deny all;

}

}

}

 

 

From mu Yushan's blog

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.