nginxDjiango 部署
时间: 2023-11-09 16:00:17 浏览: 26
为了将 Django 应用程序部署到 Nginx 上,您需要使用 uWSGI 应用程序服务器。以下是一些大致的步骤:
1. 安装 uWSGI:`pip install uwsgi`
2. 创建一个 uWSGI 配置文件,例如 myproject.ini:
```
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /path/to/your/project
# Django's wsgi file
module = myproject.wsgi
# the virtualenv (full path)
home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /path/to/your/project/myproject.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
```
3. 启动 uWSGI 进程:`uwsgi --ini myproject.ini`
4. 配置 Nginx 以将流量转发到 uWSGI 进程。在 Nginx 配置文件中添加以下行:
```
location / {
include uwsgi_params;
uwsgi_pass unix:/path/to/your/project/myproject.sock;
}
```
然后重新启动 Nginx。