File size: 3,490 Bytes
ba85f57 6c465fc 9413dbf 6c465fc 9413dbf 8ebd217 6c465fc 9413dbf 6c465fc ab2ec24 6c465fc ab2ec24 6c465fc 9413dbf e111a8f 9413dbf 8ebd217 6c465fc 9413dbf ab2ec24 6c465fc 9413dbf dfb9ca2 6c465fc 9413dbf 6c465fc ab2ec24 9413dbf ab2ec24 6c465fc 9413dbf dfb9ca2 6c465fc 9413dbf 6c465fc 9413dbf 6c465fc ab2ec24 9413dbf 6c465fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
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';
}
}
} |