nignx.conf配置说明
代码语言:txt复制具体参数说明还可以参考链接:https://www.jianshu.com/p/73061dc199dd
#一般使用创建的nginx用户组,避免使用root用户,防止被黑直接有root权限
user www www;
#一般根据cpu数量来,可以使用lscpu查看 CPU(s): 4,当然可以直接写auto自动获取
worker_processes auto;
# debug|info|notice|warn|error|crit 初始使用crit级别就行,当有比较多502信息时可以调成error或其他等级分析日志
error_log /home/wwwlogs/nginx_error.log crit;
#将 PID 输出到 /xxx/nginx.pid 文件中;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
#指定此进程可以打开的最大文件描述符的值。
#同时连接的数量受限于系统上可用的文件描述符的数量 可用 ulimit -n 查看(比如我的2C4G测试机返回 1048576)
#如果NGINX尝试打开比可用文件描述符更多的套接字,会发现error.log中出现Too many opened files的信息
worker_rlimit_nofile 51200;
events
{
use epoll;
#每个 Nginx 工作进程最大连接数(线程数)生产环境最好 > 9000
#根据系统的最大打开文件数来调整
#系统的最大打开文件数>= worker_connections*worker_process
#查看系统的最大打开文件数: ulimit -a | grep "open files"
#如返回 open files (-n) 1048576
#若此值过小(如一些1024的默认)需要修改系统变量并重启 (一般该到65535)
#参考:https://blog.csdn.net/weixin_60766221/article/details/127462231
worker_connections 51200;
#让NGINX worker能够在获得新连接的通知时尽可能多的接受连接,立即接受所有连接放到监听队列中,否则将逐个接受连接
multi_accept on;
}
http
{
#隐藏nginx版本
server_tokens off;
include mime.types;
default_type application/octet-stream;
#proxy_redirect off; ## 关闭代理重定向
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_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 "$upstream_addr" "$upstream_status" $request_time $upstream_response_time $host';
## 服务器名称哈希表的最大值
#server_names_hash_max_size 256;
## 服务器名称哈希表存储bucket大小
server_names_hash_bucket_size 128;
## 设置缓冲区以读取客户端请求标头
client_header_buffer_size 32k;
## 设置缓冲区以读取客户端请求标头最大值number和size
large_client_header_buffers 4 32k;
## 设置客户端请求body的最大允许大小
client_max_body_size 50m;
sendfile on;
## 启用长连接马上响应,提高性能 提高网络包传输的'实时性'
tcp_nodelay on;
## 打开套接字选项 提升网络包的传输'效率'(先将数据缓存至缓存区,存满再发)
tcp_nopush on;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6].";
access_log off;
include vhost/nginx_online/*.conf;
}
线上nignx.conf 配置 Demo
代码语言:txt复制一般安装配置目录在
/usr/local/nginx/conf
user www www;
worker_processes auto;
error_log /home/wwwlogs/nginx_error.log crit;
# debug|info|notice|warn|error|crit
#error_log /home/wwwlogs/nginx_error.log error;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
server_tokens off;
include mime.types;
default_type application/octet-stream;
#proxy_redirect off;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_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 "$upstream_addr" "$upstream_status" $request_time $upstream_response_time $host';
#server_names_hash_max_size 256;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6].";
access_log off;
include vhost/nginx_online/*.conf;
}