Zayn777 commited on
Commit
6f548ff
·
verified ·
1 Parent(s): 18fdfae

Create nginx.conf

Browse files
Files changed (1) hide show
  1. nginx.conf +127 -0
nginx.conf ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 全局配置
2
+ user www-data;
3
+ worker_processes auto;
4
+ worker_rlimit_nofile 51200;
5
+ error_log /var/log/nginx/error.log crit;
6
+ pid /var/run/nginx.pid;
7
+
8
+ events {
9
+ use epoll;
10
+ worker_connections 51200;
11
+ multi_accept on;
12
+ }
13
+
14
+ http {
15
+ include mime.types;
16
+ default_type application/octet-stream;
17
+ client_max_body_size 1024m;
18
+
19
+ # 日志格式
20
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
21
+ '$status $body_bytes_sent "$http_referer" '
22
+ '"$http_user_agent" "$http_x_forwarded_for"';
23
+ access_log /var/log/nginx/access.log main;
24
+
25
+ # 性能优化
26
+ sendfile on;
27
+ tcp_nopush on;
28
+ tcp_nodelay on;
29
+ keepalive_timeout 65;
30
+ types_hash_max_size 2048;
31
+
32
+ # Gzip 压缩
33
+ gzip on;
34
+ gzip_disable "msie6";
35
+ gzip_vary on;
36
+ gzip_proxied any;
37
+ gzip_comp_level 6;
38
+ gzip_buffers 16 8k;
39
+ gzip_http_version 1.1;
40
+ gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
41
+
42
+ # 代理缓存配置
43
+ proxy_cache_path /var/cache/nginx
44
+ levels=1:2
45
+ keys_zone=nginx_cache:10m
46
+ max_size=1g
47
+ inactive=24h
48
+ use_temp_path=off;
49
+
50
+ # 主服务器配置
51
+ server {
52
+ listen 80;
53
+ server_name localhost;
54
+
55
+ # 健康检查
56
+ location /health {
57
+ return 200 "OK";
58
+ }
59
+
60
+ # 根路径代理
61
+ location / {
62
+ proxy_pass http://127.0.0.1:8080;
63
+ proxy_set_header Host $host;
64
+ proxy_set_header X-Real-IP $remote_addr;
65
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
66
+ proxy_set_header X-Forwarded-Proto $scheme;
67
+
68
+ # WebSocket 支持
69
+ proxy_http_version 1.1;
70
+ proxy_set_header Upgrade $http_upgrade;
71
+ proxy_set_header Connection 'upgrade';
72
+
73
+ # WebSocket 超时设置
74
+ proxy_read_timeout 300s;
75
+ proxy_send_timeout 300s;
76
+ }
77
+
78
+ # 静态资源缓存
79
+ location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)(.*) {
80
+ proxy_pass http://127.0.0.1:8080;
81
+ proxy_set_header Host $host;
82
+ proxy_set_header X-Real-IP $remote_addr;
83
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
84
+
85
+ # 启用浏览器缓存
86
+ add_header Cache-Control "public, max-age=31536000, immutable";
87
+ }
88
+
89
+ # 模型接口缓存
90
+ location /api/models {
91
+ proxy_cache nginx_cache;
92
+ proxy_cache_key $request_uri;
93
+
94
+ # 缓存有效期为 10 分钟
95
+ proxy_cache_valid 200 10m;
96
+
97
+ # 启用后台更新
98
+ proxy_cache_background_update on;
99
+
100
+ # 在更新时允许使用过期的缓存
101
+ proxy_cache_use_stale updating;
102
+
103
+ # 检查后端内容是否已更改
104
+ proxy_cache_revalidate on;
105
+
106
+ # 至少使用一次后才缓存
107
+ proxy_cache_min_uses 1;
108
+
109
+ proxy_pass http://127.0.0.1:8080;
110
+
111
+ # 添加缓存状态头
112
+ add_header X-Cache-Status $upstream_cache_status;
113
+ }
114
+
115
+ # 排除版本检查 API 的缓存
116
+ location /api/check_version {
117
+ proxy_pass http://127.0.0.1:8080;
118
+ proxy_no_cache 1;
119
+ }
120
+
121
+ # 安全头配置
122
+ add_header X-Content-Type-Options "nosniff";
123
+ add_header X-Frame-Options "SAMEORIGIN";
124
+ add_header X-XSS-Protection "1; mode=block";
125
+ add_header Content-Security-Policy "default-src 'self';";
126
+ }
127
+ }