-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf.example
More file actions
executable file
·73 lines (64 loc) · 3.09 KB
/
nginx.conf.example
File metadata and controls
executable file
·73 lines (64 loc) · 3.09 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
server {
listen 80;
server_name your-domain.com; # 替换为您的域名
# 前端静态文件
location / {
root /path/to/your/dist; # 替换为您的dist目录路径
index index.html;
try_files $uri $uri/ /index.html;
}
# 登录接口单独代理(不使用/api前缀)
location /auth/oauth2/token {
proxy_pass http://127.0.0.1:8000/auth/oauth2/token;
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 Access-Control-Allow-Origin https://your-domain.com;
proxy_set_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
proxy_set_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;
# 处理OPTIONS请求
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin https://your-domain.com;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;
return 204;
}
}
# 其他API接口代理(生产环境中直接代理,不使用/api前缀)
location ~ ^/(admin|user|customers|projects|sales|reports)/ {
proxy_pass http://127.0.0.1:8000$request_uri;
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 Access-Control-Allow-Origin https://your-domain.com;
proxy_set_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
proxy_set_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;
# 处理OPTIONS请求
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin https://your-domain.com;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;
return 204;
}
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
root /path/to/your/dist; # 替换为您的dist目录路径
expires 1y;
add_header Cache-Control "public, immutable";
}
}
# HTTPS配置示例(可选)
# server {
# listen 443 ssl;
# server_name your-domain.com;
#
# ssl_certificate /path/to/your/cert.pem;
# ssl_certificate_key /path/to/your/key.pem;
#
# # 其他配置与上面相同
# }