-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
79 lines (68 loc) · 2.18 KB
/
Copy pathnginx.conf
File metadata and controls
79 lines (68 loc) · 2.18 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
events {
worker_connections 1024;
}
http {
upstream app {
server app:8000;
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 5678;
server_name _;
# 日志配置
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# 根路径重定向到 /2025
location = / {
if ($http_x_forwarded_proto = "") {
set $real_scheme $scheme;
}
if ($http_x_forwarded_proto != "") {
set $real_scheme $http_x_forwarded_proto;
}
if ($http_x_forwarded_host = "") {
set $real_host $host;
}
if ($http_x_forwarded_host != "") {
set $real_host $http_x_forwarded_host;
}
return 302 $real_scheme://$real_host/2025/;
}
# 静态文件和媒体文件服务
location ~ ^/2025/(static|media)/ {
root /data/pycon;
expires 1d;
add_header Cache-Control "public";
}
# /2025 和 /admin 路由到 Django 应用
location ~ ^/(2025|admin) {
if ($http_x_forwarded_proto = "") {
set $real_scheme $scheme;
}
if ($http_x_forwarded_proto != "") {
set $real_scheme $http_x_forwarded_proto;
}
if ($http_x_forwarded_host = "") {
set $real_host $host;
}
if ($http_x_forwarded_host != "") {
set $real_host $http_x_forwarded_host;
}
proxy_pass http://app;
proxy_set_header Host $real_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 $real_scheme;
proxy_redirect off;
client_max_body_size 100M;
}
# 其余情况服务 /data/pycon 目录
location / {
root /data/pycon;
try_files $uri $uri/ =404;
expires 30d;
add_header Cache-Control "public";
}
}
}