思路
- 我这里以music和website两个项目为例
- 这里以通过windows去访问Centos部署的项目为例
- 相对于部署一个Django项目,部署两个Django需要做的只是修改uwsgi和nginx配置文件
- 单个Django项目部署链接:link
步骤
music项目的uwsgi配置
相对于部署一个Django项目的uwsgi配置来说,只有一处(可能需要修改)要注意的,就是socket参数,只需要分配一个端口对应nginx的uwsgi_pass参数即可(这个8004看个人分配即可,winodws并不是通过这个端口去访问项目的)
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# 项目的路径(绝对路径),根据自己项目位置来写
chdir = /root/django-music/music
# 项目的wsgi文件
module = music.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe)
# 这里的socket是用于连接nginx的,是与nginx对应的
socket = 127.0.0.1:8004 #需要注意的地方
# clear environment on exit(这一句其实不是很懂,不过也没关系)
vacuum = true
# 虚拟环境目录 (绝对路径)
virtualenv = /root/.virtualenvs/music
website项目的uwsgi配置
同上,只需要注意socket参数
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /root/django-website/Project
# Django's wsgi file
module = Project.wsgi
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8003 #需要注意的地方
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = /root/.virtualenvs/website
nginx的配置
nginx的配置中需要修改的是:
1、添加多一个server
2、修改listen对应的端口号(windows通过server_name:listen来访问Django项目)
3、uwsgi_pass参数和uwsgi的socket参数对应
4、注意端口号不要冲突,还有在阿里云Centos服务器安全组规则中需要开启对应的端口
我是在windows中通过39.108.91.173:8001访问website项目,39.108.91.173:8002访问music项目,至此两个Django项目部署就完成了
# configuration of the server
# website
server {
# the port your site will be served on
listen 8001; #需要修改的地方
# the domain name it will serve for
server_name 39.108.91.173; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /root/django-website/Project/media; # 指向django的media目录
}
location /static {
alias /root/django-website/Project/static; # 指向django的static目录
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass 127.0.0.1:8003; #需要注意的地方
include uwsgi_params; # the uwsgi_params file you installed
}
}
# music
server {
# the port your site will be served on
listen 8002; #需要修改的地方
# the domain name it will serve for
server_name 39.108.91.173; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /root/django-music/music/media; # 指向django的media目录
}
location /static {
alias /root/django-music/music/static; # 指向django的static目录
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass 127.0.0.1:8004; #需要注意的地方
include uwsgi_params; # the uwsgi_params file you installed
}
}