User www; #定义Nginx运行的用户和用户组
Worker_processes 2; #nginx进程数, the recommended setting is equal to the total CPU core number.
#error_log Logs/error.log; Global error Log definition type
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid; Process files
Events {Maximum number of working modes and connections
Worker_connections 2048; Maximum number of connections per process (max connections = number of connections * processes)
Use Epoll; event handling mechanism (EPOLL): High-performance network I/O model in System kernel 2.6, concurrent number is large, socket connection more Web server uses
Epoll is the best. If you run on FreeBSD, use the Kqueue model.
#参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | select | poll];
}
#设定http服务器
HTTP {
Include Mime.types; #文件扩展名与文件类型映射表
Default_type Application/octet-stream; #默认文件类型
CharSet Utf-8; #默认编码
Sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, and for normal applications to be set to ON, if it is used for downloading applications such as disk IO heavy load applications, can be off to balance disk and network I/O processing speed, Reduce the load on the system. Note: If the picture does not appear normal, change this to off.
AutoIndex on; #开启目录列表访问, the appropriate download server, the default shutdown.
Tcp_nopush on; #防止网络阻塞
Tcp_nodelay can effectively improve the real-time response of data
Keepalive_timeout 120; #长连接超时时间, Unit is seconds
#自定义日志格式
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
# Access_log/home/access.log Main;
gzip on; #开启gzip压缩输出
After gzip compression, the page size can be changed to 30% or smaller, so users can browse the page at a much faster speed. Gzip Compression page requires both browser and server support, in fact, server-side compression, uploaded to the browser after the browser decompression and parsing. Liu
Gzip_min_length 1k; Sets the minimum number of bytes of pages allowed to compress, and the number of page bytes is obtained from the header content-length. The default value is 0, regardless of the number of pages in most compression. It is recommended to set the number of bytes greater than 1k, which may be more or less larger than 1k.
Gzip_buffers 64k; #压缩缓冲区-//Setup System gets several units of cache used to store the compressed result data stream for gzip. 4 16k represents a 16k unit, with the original data size of 4 times times 16k of memory.
Gzip_http_version 1.1; #压缩版本 (default 1.1, front End If squid2.5 please use 1.0)
Gzip_comp_level 6; #压缩等级, 1 compression ratio is the smallest, the fastest transmission, 9 compression ratio is bigger, the transmission speed is the slowest, better CPU
Gzip_types text/plain application/x-javascript text/css application/xml; compression type
Gzip_vary on;/and HTTP headers have a relationship, add a vary header, to the proxy server, some browsers support compression, and some do not support, so avoid wasting does not support compression, so according to the client's HTTP header to determine whether the need to compress
server {
# listen default;
# server_name_;
# return 500;
Underscores_in_headers on;
Listen 80;
server_name node.convert.com;
Access_log/home/host.access.log main;
Location/{
root/var/www/html;
Index index.html index.htm;
}
===========================================================================================
Reverse Proxy
User www;
Worker_processes 2;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;
Events {
Worker_connections 2048;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
# Access_log/home/access.log Main;
Sendfile on;
CharSet Utf-8;
Tcp_nopush on;
#keepalive_timeout 0;
Keepalive_timeout 65;
# tcp_nodely on;
gzip on;
Gzip_min_length 1k;
Gzip_buffers 64k;
Gzip_http_version 1.1;
Gzip_comp_level 6;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Client_max_body_size 100;/allows the client to request the maximum number of individual file bytes, which appears in the Content-length field of the request header. (You can change this parameter to limit the user's upload file size)
The maximum number of bytes requested by the Client_body_buffer_size 512k;\\ buffer proxy buffer is understood to be saved to local and then passed to the user. This instruction can specify the buffer size used by the connection request, the default value: 8k/16k. If the client requests a file larger than 128k, Nginx tries to create a temporary file on the hard disk. If the hard drive is full, an error will be made
Proxy_connect_timeout 600s; \ \ Timeout for connection to backend server, initiates handshake wait response time-out
Proxy_read_timeout 600s; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ " Default value:
Proxy_send_timeout 600s;\\ back-end server return time _ is within the specified time, the backend server must pass all the data. Set the proxy server forward request time-out, also refers to the completion of two handshake after the time, if more than this time the proxy server does not have data forwarding to the back-end server, Nginx will close the connection.
Proxy_buffer_size 32k;\\ Proxy Request Buffer _ This cache interval will save the user's header information to provide nginx for rule processing. Generally as long as you can save the head information. Default value: Proxy_buffer_size 4k/8k. Sets the buffer size for the first portion of the reply read from the backend server, which typically contains a small answer header.
Proxy_buffers 4 32k;\\ Sets the number and size of buffers used to read the answer (from the back-end server), telling Nginx to save a single buffer of a few, up to how much space
Proxy_busy_buffers_size 64k;\\ If the system is very busy can apply for a larger proxy_buffers, official recommendation
Proxy_temp_file_write_size 64k; \ \ Sets the size of cache Pro file data when writing to Proxy_temp_path, preventing a worker process from blocking too long when passing files
Proxy_temp_path/dev/shm/proxy_temp; \ \ \ Similar to the Client_body_temp_path directive in the HTTP core module, specify a directory to buffer larger proxy requests.
Three ways to do the opposite
One: include extra/upstream01.conf;
upstream01.conf;
server {
# underscores_in_headers on;
# Listen 80;
# server_name node. convert.com;
# Access_log/home/host2.access.log Main;
#
# location/{
# Proxy_pass http://www.51cto.com/;
# Proxy_set_header Host $host;
# proxy_redirect off;
# Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503 http_504 http_404;
# }
Two:
Upstream Node1_convert_pool {
# server 192.168.1.210:80;
# }
# upstream Node2_convert_pool {
# server 192.168.1.211:80;
# }
# server {
# underscores_in_headers on;
# Listen 80;
# server_name node.convert.com;
# Access_log/home/host1.access.log Main;
#
# location/{
# Proxy_pass http://node1.convert.com;
# Proxy_set_header Host $host;
# proxy_redirect off;
# Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503 http_504 http_404;
# }
#
# }
# server {
# underscores_in_headers on;
# Listen 80;
# server_name node2.convert.com;
# Access_log/home/host2.access.log Main;
#
# location/{
# Proxy_pass http://node2_convert_pool/;
# Proxy_set_header Host $host;
# proxy_redirect off;
# Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503 http_504 http_404;
# }
#
#
# }
}
Three:
server {
# underscores_in_headers on;
# Listen 80;
# server_name node. convert.com;
# Access_log/home/host2.access.log Main;
#
# location/{
# Proxy_pass http://www.51cto.com/;
# Proxy_set_header Host $host;
# proxy_redirect off;
# Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503 http_504 http_404;
# }
#
This article is from the "Crazy_sir" blog, make sure to keep this source http://douya.blog.51cto.com/6173221/1541615