Files
shop-platform/docker/nginx/ref/nginx.conf
2025-10-28 18:23:50 +08:00

76 lines
4.5 KiB
Nginx Configuration File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# /etc/nginx/nginx.conf
# Nginx 的主配置文件(通常是 /etc/nginx/nginx.conf变更的修改
############################################
# user nginx;
# worker_processes auto;
# events {
# worker_connections 1024;
# }
# http {
# include /etc/nginx/conf.d/*.conf; # 加载其他配置
# }
#############################################
user www www; # 运行nginx的用户和组
worker_processes auto; # 自动设置工作进程数量建议等于CPU核数
error_log /www/wwwlogs/nginx_error.log crit; # 错误日志路径及最低记录级别
pid /tmp/nginx.pid; # 主进程PID文件位置
worker_rlimit_nofile 51200; # 提高工作进程可打开的最大文件描述符数
events { # 事件模块开始
use epoll; # 指定事件驱动模型Linux上推荐epoll
worker_connections 51200; # 每个工作进程允许的最大连接数
multi_accept on; # 允许一次接收多个新连接
} # 事件模块结束
http { # HTTP 主配置块开始
include mime.types; # 引入MIME类型映射文件
#include luawaf.conf; # 可选Lua防火墙配置当前被注释
include conf.c/proxy.conf; # 引入反向代理或公共设置
default_type application/octet-stream; # 默认MIME类型
server_names_hash_bucket_size 512; # server_name哈希桶大小影响域名匹配性能
client_header_buffer_size 32k; # 单个请求头的缓冲区大小
large_client_header_buffers 4 32k; # 用于大请求头的缓冲区数量与大小
client_max_body_size 50m; # 客户端请求体最大尺寸(上传限制)
sendfile on; # 启用高效文件传输sendfile
tcp_nopush on; # 优化TCP以减少分片与sendfile配合
keepalive_timeout 60; # keep-alive连接超时时间
tcp_nodelay on; # 关闭Nagle算法以减少小包延迟
fastcgi_connect_timeout 300; # FastCGI连接超时
fastcgi_send_timeout 300; # 发送给FastCGI的超时
fastcgi_read_timeout 300; # 从FastCGI读取响应的超时
fastcgi_buffer_size 64k; # FastCGI响应头缓冲区大小
fastcgi_buffers 4 64k; # FastCGI响应的缓冲区数量和单个大小
fastcgi_busy_buffers_size 128k; # FastCGI忙时缓冲区总大小避免磁盘写入
fastcgi_temp_file_write_size 256k; # 写入临时文件前允许的阈值大小
fastcgi_intercept_errors on; # 由nginx处理后端返回的错误页面
gzip on; # 启用gzip压缩响应
gzip_min_length 1k; # 小于该长度的响应不做压缩
gzip_buffers 4 16k; # gzip压缩时使用的缓冲区数量与大小
gzip_http_version 1.1; # 最低支持的HTTP版本以启用gzip
gzip_comp_level 2; # gzip压缩级别1-9数值越大CPU越高
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; # 要压缩的内容类型
gzip_vary on; # 添加Vary: Accept-Encoding头以支持缓存代理
gzip_proxied expired no-cache no-store private auth; # 在代理情况下是否对响应进行gzip
gzip_disable "MSIE [1-6]\."; # 对老旧IE浏览器禁用gzip
limit_conn_zone $binary_remote_addr zone=perip:10m; # 基于客户端IP的连接数限制共享内存区
limit_conn_zone $server_name zone=perserver:10m; # 基于server_name虚拟主机的连接数限制共享内存区
server_tokens off; # 禁止在响应和错误页中显示nginx版本
access_log off; # 关闭访问日志(可根据需求启用)
include sites-enabled/*.conf; # 引入启用的站点(虚拟主机)配置
} # HTTP 主配置块结束