na / nginx.conf
rclon's picture
Update nginx.conf
ab2ec24 verified
worker_processes auto;
# 设置最大打开文件数
worker_rlimit_nofile 65535;
events {
# 每个工作进程的最大连接数
worker_connections 65535;
# 启用多路复用
multi_accept on;
# 使用高效的事件处理模型
use epoll;
}
http {
# 连接超时设置
keepalive_timeout 65;
keepalive_requests 100;
# 压缩设置
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
# 日志配置
access_log /tmp/nginx_access.log;
error_log /tmp/nginx_error.log;
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
# MIME类型
include /etc/nginx/mime.types;
# 性能优化的upstream配置
upstream backend {
least_conn; # 最少连接负载均衡
server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
keepalive 32; # 保持的后端连接数
}
server {
listen 7860 reuseport; # 启用端口重用
listen [::]:7860 reuseport;
server_name localhost;
location /hf/ {
rewrite ^/hf/(.*)$ /$1 break;
limit_req zone=one burst=15 nodelay;
limit_conn addr 5;
proxy_pass http://backend;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
# 清除敏感头部
proxy_set_header X-Forwarded-For "";
proxy_set_header X-Real-IP "";
proxy_set_header X-Direct-Url "";
proxy_set_header X-Forwarded-Port "";
proxy_set_header X-Ip-Token "";
proxy_set_header X-Request-Id "";
proxy_set_header X-Amzn-Trace-Id "";
proxy_set_header X-Forwarded-Proto "";
# 代理优化
proxy_buffering off;
proxy_cache off;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
error_page 503 =429 /429.html;
}
location / {
limit_req zone=one burst=20 nodelay;
limit_conn addr 10;
proxy_pass http://backend;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
# 清除敏感头部
proxy_set_header X-Forwarded-For "";
proxy_set_header X-Real-IP "";
proxy_set_header X-Direct-Url "";
proxy_set_header X-Forwarded-Port "";
proxy_set_header X-Ip-Token "";
proxy_set_header X-Request-Id "";
proxy_set_header X-Amzn-Trace-Id "";
proxy_set_header X-Forwarded-Proto "";
# 代理优化
proxy_buffering off;
proxy_cache off;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
error_page 503 =429 /429.html;
}
# 429 错误页面
location = /429.html {
return 429 'Too Many Requests';
}
}
}