[root@ubuntu ~]# cat /usr/local/nginx1.27/conf/nginx.conf
user www;
worker_processes auto;
pid /run/nginx.pid;
# 避免 nginx 出现 worker_connections are not enough 报错
worker_rlimit_nofile 655360;
events {
worker_connections 65535;
use epoll;
multi_accept on;
}
http {
# 设置CDN服务器的IP地址范围
set_real_ip_from 0.0.0.0/0;
# 使用CDN传递的第一个IP作为真实IP
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
include mime.types;
log_format main '{ "@timestamp": "$time_iso8601", '
'"remote_addr": "$remote_addr", '
'"request_method": "$request_method", '
'"uri": "$uri", '
'"body_bytes_sent": $body_bytes_sent, '
'"request_time": $request_time, '
'"upstream_response_time": "$upstream_response_time", '
'"status": "$status", '
'"upstream_status": "$upstream_status", '
'"request": "$request", '
'"http_referrer": "$http_referer", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_user_agent": "$http_user_agent", '
'"host": "$host", '
'"server_port": "$server_port", '
'"upstream_addr": "$upstream_addr", '
'"scheme": "$scheme" }';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;
client_header_buffer_size 4k;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
client_header_timeout 15;
client_body_timeout 15;
reset_timedout_connection on;
send_timeout 150;
server_tokens off;
client_max_body_size 1024m;
types_hash_max_size 4096;
gzip on;
gzip_vary on;
gzip_min_length 1k;
gzip_buffers 16 16k;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_temp_path nginx_tmp;
fastcgi_intercept_errors on;
fastcgi_cache_path fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;
proxy_buffering on;
proxy_buffers 16 32k;
proxy_buffer_size 32k;
proxy_cache_path cache levels=1:2 keys_zone=cache:10m max_size=10g inactive=60m use_temp_path=off;
# 定义全局请求限制区域
# $binary_remote_addr: 客户端 IP 地址(用二进制表示)
# zone=one:10m: 使用一个名为 one 的 zone,大小为 10MB
# rate=50r/s: 每秒钟只允许 50 个请求
limit_req_zone $binary_remote_addr zone=one:100m rate=50r/s;
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript application/json application/rss+xml
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
include vhosts/*.conf;
}