-
Notifications
You must be signed in to change notification settings - Fork 9
/
nginx.proj.conf
89 lines (77 loc) · 2.44 KB
/
nginx.proj.conf
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
upstream uwsgi {
# server unix:///tmp/demo.sock;
server ${BACKEND_HOST};
}
# 如果是 80 端口访问的,跳转到 https
server {
listen 80;
server_name naivegenerator.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name naivegenerator.com;
access_log /var/log/nginx/demo.access.log;
error_log /var/log/nginx/demo.error.log;
charset utf-8;
client_max_body_size 75M;
# ssl 文件的目录,可以任意指定
ssl_certificate /root/certs/certificate.crt;
ssl_certificate_key /root/certs/private.key;
# 管理员地址的转发
location /admin/ {
proxy_http_version 1.1;
proxy_pass http://uwsgi;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_redirect off;
}
# 管理员地址静态文件
location /static/admin/ {
# 使用后端给共享的目录
alias /demo-backend/static/admin/;
# 实际产品部署时不能直接共享,我会在 Dockerfile 中把静态文件复制到前端根目录
# alias /demo-frontend/admin_static/;
}
# rest framework 的静态文件
location /static/rest_framework/ {
alias /demo-backend/static/rest_framework/;
# alias /demo-frontend/rest_static/;
}
# 主页静态文件
location / {
root /demo-frontend/build;
index index.html index.htm;
}
# api 跳转
location /api/ {
proxy_http_version 1.1;
proxy_pass http://uwsgi; # 等于直接跳转到 http://127.0.0.1:8000
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_redirect off;
# 也可以使用 django 的 uwsgi 配置
# include /etc/nginx/uwsgi_params;
# uwsgi_pass uwsgi;
}
}