Nginx+uWSGI部署多个Django项目

uWSGI配置

project_1 的 uWSGI 的配置文件 project_1.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[uwsgi]

chdir = /project_1/

module = project_1.wsgi

master = true

processes = 10

socket = /project_1/project_1.sock

chmod-socket = 666
chown-socket = role_1:role_1

enable-threads=true

die-on-term = true

project_n 的 uWSGI 的配置文件 project_n.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[uwsgi]

chdir = /project_n/

module = project_n.wsgi

master = true

processes = 10

socket = /project_n/project_n.sock

chmod-socket = 666
chown-socket = role_n:role_n

enable-threads=true

die-on-term = true

Nginx配置

nginx.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
server {
listen 80;

root /usr/share/nginx/www/public;
index index.php index.html index.htm;

server_name 127.0.0.1 x.x.x.x;
include blocksip.conf;
location / {
try_files $uri $uri/ /index.html;
}

error_page 404 /404.html;

location /project_1 {
include uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass unix:/project_1/project_1.sock;
uwsgi_param SCRIPT_NAME /project_1;
uwsgi_param UWSGI_SCRIPT project_1.wsgi;
uwsgi_modifier1 30;
uwsgi_read_timeout 1800s;
uwsgi_send_timeout 1800s;
}

location /project_1/media/ {
alias /usr/share/nginx/www/django_static/project_1/media/;
}

location /project_1/static/ {
alias /usr/share/nginx/www/django_static/project_1/;
}

location /apk/ {
alias /usr/share/nginx/www/django_static/project_1/apk/online/;
}

location /project_n {
include uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass unix:/project_n/project_n.sock;
uwsgi_param SCRIPT_NAME /project_n;
uwsgi_param UWSGI_SCRIPT project_n.wsgi;
uwsgi_modifier1 30;
uwsgi_read_timeout 1800s;
uwsgi_send_timeout 1800s;
}

location /project_n/media/ {
alias /usr/share/nginx/www/django_static/project_n/media/;
}

location /project_n/static/ {
alias /usr/share/nginx/www/django_static/project_n/;
}

location /apk_project_n/ {
alias /usr/share/nginx/www/django_static/project_n/apk/online/;
}
}

nginx配置首页默认跳转路径

https指定路径跳转

1
rewrite ^/index.html(.*)$ 指定的跳转路径 permanent;

http跳转到https

1
2
3
4
5
6
7
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
location / {
index index.html index.htm;
}