-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathnginx.conf
More file actions
106 lines (91 loc) · 3.58 KB
/
nginx.conf
File metadata and controls
106 lines (91 loc) · 3.58 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
99
100
101
102
103
104
105
106
server {
listen 80;
listen [::]:80;
server_name _;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
resolver $NAMESERVERS ipv6=off;
add_header X-Content-Type-Options "nosniff" always;
# add_header X-Frame-Options "SAMEORIGIN" always; # 防止点击劫持
proxy_hide_header X-Frame-Options;
add_header X-XSS-Protection "1; mode=block" always; # 启用XSS过滤
add_header Referrer-Policy "strict-origin-when-cross-origin" always; # 控制Referer信息
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # 启用HSTS
# add_header Content-Security-Policy "default-src 'self'; img-src 'self' data:; script-src 'self' 'unsafe-inline' http://at.alicdn.com; style-src 'self' 'unsafe-inline';" always;
# add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
server_tokens off;
include /etc/nginx/mime.types;
set $my_result_code 200;
set $my_server_name {SERVER_NAME};
if ($http_Host !~* ^{SERVER_NAME}) {
set $my_result_code 403;
}
if ($my_server_name ~ "0") {
set $my_result_code 200;
}
if ($my_result_code = 403) {
return 403;
}
location / {
autoindex off;
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
}
location ^~/api/ {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE, PATCH";
add_header Access-Control-Allow-Headers "Authorization, Content-Type";
if ($request_method = 'OPTIONS') {
return 204;
}
proxy_pass {API_BASE_PATH};
# if ($request_uri ~* ^/api/(.*)$) {
# proxy_pass {API_BASE_PATH}$1;
# }
#proxy_pass http://host.docker.internal:8840/;
proxy_set_header X-Forwarded-Proto $scheme;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1;
proxy_buffering off;
chunked_transfer_encoding off;
proxy_cache off;
proxy_send_timeout 30m;
proxy_read_timeout 30m;
client_max_body_size 1024m;
client_body_buffer_size 1024k;
}
location ~* ^/(?!api/|amap/)[^/]+/(.+\.(?:ico|css|js|gif|jpe?g|png|webp|avif|woff2?|eot|ttf|svg|otf|map|json|txt|wasm))$ {
root /usr/share/nginx/html;
try_files $uri /$1 =404;
expires 6M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|webp|avif|woff2?|eot|ttf|svg|otf|map|json|txt|wasm)$ {
root /usr/share/nginx/html; # 确保路径正确
expires 6M;
access_log off;
add_header Cache-Control "public";
}
location ~* ^/amap/ { # 避免高德地图静态资源
expires 1h;
add_header Cache-Control "no-cache";
}
location ~ /\.(?!well-known).* { # 禁止访问敏感文件
deny all;
}
error_page 404 /index.html;
}