-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
98 lines (81 loc) · 3.11 KB
/
nginx.conf
File metadata and controls
98 lines (81 loc) · 3.11 KB
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
# HTTP 服务器 - 将所有 HTTP 请求重定向到 HTTPS
server {
listen 80;
listen [::]:80;
server_name cdn.yourdomain.com; # 替换为你的域名
# 将所有 HTTP 请求重定向到 HTTPS
location / {
return 301 https://$server_name$request_uri;
}
}
# HTTPS 服务器
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cdn.yourdomain.com; # 替换为你的域名
# SSL 配置
ssl_certificate /etc/nginx/ssl/cdn.yourdomain.com.crt; # 替换为你的证书路径
ssl_certificate_key /etc/nginx/ssl/cdn.yourdomain.com.key; # 替换为你的私钥路径
# SSL 优化配置
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# 现代 SSL 配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# HSTS 配置
add_header Strict-Transport-Security "max-age=63072000" always;
# 基本安全头
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# 反向代理缓冲区配置
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
# 超时配置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# 文件上传大小限制
client_max_body_size 100M;
# 主要的反向代理配置
location / {
proxy_pass http://127.0.0.1:5000; # 替换为你的应用程序实际运行的地址和端口
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "";
# WebSocket 支持
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 状态监控接口配置
location /api/status {
proxy_pass http://127.0.0.1:5000; # 替换为你的应用程序实际运行的地址和端口
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 静态文件缓存配置
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
proxy_pass http://127.0.0.1:5000; # 替换为你的应用程序实际运行的地址和端口
proxy_http_version 1.1;
proxy_set_header Host $host;
# 静态文件缓存设置
expires 7d;
add_header Cache-Control "public, no-transform";
}
# 禁止访问 . 文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}