Spaces:
Sleeping
Sleeping
Update nginx.conf
Browse files- nginx.conf +79 -31
nginx.conf
CHANGED
|
@@ -1,63 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
events {
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
}
|
| 4 |
|
| 5 |
http {
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
keepalive_timeout 65;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
server {
|
| 12 |
-
listen
|
|
|
|
| 13 |
server_name localhost;
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
location /hf/ {
|
| 16 |
-
# 删除 /hf
|
| 17 |
rewrite ^/hf/(.*)$ /$1 break;
|
| 18 |
|
| 19 |
-
|
| 20 |
-
proxy_pass http://127.0.0.1:3000;
|
| 21 |
proxy_http_version 1.1;
|
| 22 |
proxy_set_header Upgrade $http_upgrade;
|
| 23 |
proxy_set_header Connection "upgrade";
|
| 24 |
proxy_set_header Host $host;
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
proxy_set_header X-Forwarded-For "";
|
| 28 |
-
proxy_set_header X-Real-IP "";
|
| 29 |
-
proxy_set_header X-Direct-Url "";
|
| 30 |
-
proxy_set_header X-Forwarded-Port "";
|
| 31 |
-
proxy_set_header X-Ip-Token "";
|
| 32 |
-
proxy_set_header X-Request-Id "";
|
| 33 |
-
proxy_set_header X-Amzn-Trace-Id "";
|
| 34 |
-
proxy_set_header X-Forwarded-Proto "";
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
proxy_buffering off;
|
| 38 |
proxy_cache off;
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
location / {
|
| 42 |
-
|
| 43 |
-
proxy_pass http://127.0.0.1:3000;
|
| 44 |
proxy_http_version 1.1;
|
| 45 |
proxy_set_header Upgrade $http_upgrade;
|
| 46 |
proxy_set_header Connection "upgrade";
|
| 47 |
proxy_set_header Host $host;
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
proxy_set_header X-Forwarded-For "";
|
| 51 |
-
proxy_set_header X-Real-IP "";
|
| 52 |
-
proxy_set_header X-Direct-Url "";
|
| 53 |
-
proxy_set_header X-Forwarded-Port "";
|
| 54 |
-
proxy_set_header X-Ip-Token "";
|
| 55 |
-
proxy_set_header X-Request-Id "";
|
| 56 |
-
proxy_set_header X-Amzn-Trace-Id "";
|
| 57 |
-
proxy_set_header X-Forwarded-Proto "";
|
| 58 |
|
|
|
|
| 59 |
proxy_buffering off;
|
| 60 |
proxy_cache off;
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
-
}
|
|
|
|
| 1 |
+
user nginx;
|
| 2 |
+
# 根据CPU核心数设置工作进程数
|
| 3 |
+
worker_processes auto;
|
| 4 |
+
|
| 5 |
+
# 设置最大打开文件数
|
| 6 |
+
worker_rlimit_nofile 65535;
|
| 7 |
+
|
| 8 |
events {
|
| 9 |
+
# 每个工作进程的最大连接数
|
| 10 |
+
worker_connections 65535;
|
| 11 |
+
|
| 12 |
+
# 启用多路复用
|
| 13 |
+
multi_accept on;
|
| 14 |
+
|
| 15 |
+
# 使用高效的事件处理模型
|
| 16 |
+
use epoll;
|
| 17 |
}
|
| 18 |
|
| 19 |
http {
|
| 20 |
+
# 优化性能的基本设置
|
| 21 |
+
sendfile on;
|
| 22 |
+
tcp_nopush on;
|
| 23 |
+
tcp_nodelay on;
|
| 24 |
+
|
| 25 |
+
# 连接超时设置
|
| 26 |
keepalive_timeout 65;
|
| 27 |
+
keepalive_requests 100;
|
| 28 |
+
|
| 29 |
+
# 压缩设置
|
| 30 |
+
gzip on;
|
| 31 |
+
gzip_vary on;
|
| 32 |
+
gzip_proxied any;
|
| 33 |
+
gzip_comp_level 6;
|
| 34 |
+
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
| 35 |
+
|
| 36 |
+
# 日志配置
|
| 37 |
+
access_log /tmp/nginx_access.log;
|
| 38 |
+
error_log /tmp/nginx_error.log;
|
| 39 |
+
|
| 40 |
+
# MIME类型
|
| 41 |
+
include /etc/nginx/mime.types;
|
| 42 |
+
|
| 43 |
+
# 性能优化的upstream配置
|
| 44 |
+
upstream backend {
|
| 45 |
+
least_conn; # 最少连接负载均衡
|
| 46 |
+
server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
|
| 47 |
+
keepalive 32; # 保持的后端连接数
|
| 48 |
+
}
|
| 49 |
|
| 50 |
server {
|
| 51 |
+
listen 8080 reuseport; # 启用端口重用
|
| 52 |
+
listen [::]:8080 reuseport;
|
| 53 |
server_name localhost;
|
| 54 |
|
| 55 |
+
# 连接限制
|
| 56 |
+
limit_conn_zone $binary_remote_addr zone=addr:10m;
|
| 57 |
+
limit_conn addr 100;
|
| 58 |
+
|
| 59 |
location /hf/ {
|
|
|
|
| 60 |
rewrite ^/hf/(.*)$ /$1 break;
|
| 61 |
|
| 62 |
+
proxy_pass http://backend;
|
|
|
|
| 63 |
proxy_http_version 1.1;
|
| 64 |
proxy_set_header Upgrade $http_upgrade;
|
| 65 |
proxy_set_header Connection "upgrade";
|
| 66 |
proxy_set_header Host $host;
|
| 67 |
|
| 68 |
+
# 清除敏感头部
|
| 69 |
+
proxy_set_header X-Forwarded-For "";
|
| 70 |
+
proxy_set_header X-Real-IP "";
|
| 71 |
+
proxy_set_header X-Direct-Url "";
|
| 72 |
+
proxy_set_header X-Forwarded-Port "";
|
| 73 |
+
proxy_set_header X-Ip-Token "";
|
| 74 |
+
proxy_set_header X-Request-Id "";
|
| 75 |
+
proxy_set_header X-Amzn-Trace-Id "";
|
| 76 |
+
proxy_set_header X-Forwarded-Proto "";
|
| 77 |
+
|
| 78 |
+
# 代理优化
|
| 79 |
proxy_buffering off;
|
| 80 |
proxy_cache off;
|
| 81 |
+
proxy_connect_timeout 60s;
|
| 82 |
+
proxy_send_timeout 60s;
|
| 83 |
+
proxy_read_timeout 60s;
|
| 84 |
}
|
| 85 |
|
| 86 |
location / {
|
| 87 |
+
proxy_pass http://backend;
|
|
|
|
| 88 |
proxy_http_version 1.1;
|
| 89 |
proxy_set_header Upgrade $http_upgrade;
|
| 90 |
proxy_set_header Connection "upgrade";
|
| 91 |
proxy_set_header Host $host;
|
| 92 |
|
| 93 |
+
# 清除敏感头部
|
| 94 |
+
proxy_set_header X-Forwarded-For "";
|
| 95 |
+
proxy_set_header X-Real-IP "";
|
| 96 |
+
proxy_set_header X-Direct-Url "";
|
| 97 |
+
proxy_set_header X-Forwarded-Port "";
|
| 98 |
+
proxy_set_header X-Ip-Token "";
|
| 99 |
+
proxy_set_header X-Request-Id "";
|
| 100 |
+
proxy_set_header X-Amzn-Trace-Id "";
|
| 101 |
+
proxy_set_header X-Forwarded-Proto "";
|
| 102 |
|
| 103 |
+
# 代理优化
|
| 104 |
proxy_buffering off;
|
| 105 |
proxy_cache off;
|
| 106 |
+
proxy_connect_timeout 60s;
|
| 107 |
+
proxy_send_timeout 60s;
|
| 108 |
+
proxy_read_timeout 60s;
|
| 109 |
}
|
| 110 |
}
|
| 111 |
+
}
|