#nginx开启的进程数
worker_processes 4; #4核CPU
#定义全局错误日志定义类型,[debug|info|notice|warn|crit]
error_log logs/error.log info;
error_log logs/error.log info;
##指定进程ID存储文件位置
pid logs/nginx.pid;
pid logs/nginx.pid;
events {
#use[kqueue|rtsig|epoll|/dev/poll|select|poll];
use epoll;
use epoll;
#每个进程可以处理的最大连接数
worker_connections 1024;
#worker工作方式:串行
multi_accept on;
}
worker_connections 1024;
#worker工作方式:串行
multi_accept on;
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
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"';
#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 logs/access.log main;
#access_log logs/access.log main;
#高效传输
sendfile on;
sendfile on;
#更为严重的错误日志,减少IO压力
error_log logs/error.log crit;
error_log logs/error.log crit;
#关闭日志
#ccess_log off;
#ccess_log off;
#默认编码
#charset utf-8;
#charset utf-8;
#服务器名字的hash表大小
server_names_hash_bucket_size 128;
server_names_hash_bucket_size 128;
#客户端请求单个文件的最大字节数
client_header_buffer_size 32k;
#指定客户端请求中较大的消息头的缓存最大数量和大小。
large_client_header_buffers 4 64k;
#防止网络阻塞
tcp_nopush on;
tcp_nodelay on;
client_header_buffer_size 32k;
#指定客户端请求中较大的消息头的缓存最大数量和大小。
large_client_header_buffers 4 64k;
#防止网络阻塞
tcp_nopush on;
tcp_nodelay on;
#客户端连接超时时间,单位是秒
keepalive_timeout 60;
keepalive_timeout 60;
#客户端请求头读取超时时间
client_header_timeout 10;
client_header_timeout 10;
#设置客户端请求主体读取超时时间
client_body_timeout 10;
client_body_timeout 10;
#响应客户端超时时间
send_timeout 10;
send_timeout 10;
#limit模块
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
#隐藏响应header和错误通知中的版本号
server_tokens off;
server_tokens off;
upstream node {
server 192.168.4.104 weight=1 max_fails=2 fail_timeout=30s;
}
server 192.168.4.104 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
index index.html;
location / {
proxy_pass http://node;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
listen 80;
server_name localhost;
index index.html;
location / {
proxy_pass http://node;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
#连接超时时间
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
#开启缓存
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
proxy_max_temp_file_size 256k;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
proxy_max_temp_file_size 256k;
}
#错误信息返回页面
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}