- 前置條件:/root/mysite目錄下有個(gè)名為mhwl的django項(xiàng)目
- 復(fù)制/etc/nginx/目錄下的uwsgi_params到站點(diǎn)目錄下
sudo cp /etc/nginx/uwsgi_params /root/mysite/mhwl/
- 在 /root/mysite/mhwl/ 下創(chuàng)建uwsgi.ini邓萨,并輸入內(nèi)容
[uwsgi]
socket=mhwl.sock
chdir=/root/mysite/mhwl
wsgi-file=mhwl/wsgi.py
process=4
threads=2
master=True
vacuum=True
pidfile=uwsgi.pid
daemonize=uwsgi.log
plugins = python3
- 在/root/mysite/mhwl/ 下創(chuàng)建mhwl_nginx.conf破托,輸入內(nèi)容(也可以修改/etc/nginx/nginx.conf仗岸,這里選擇了更酷一點(diǎn)的,在項(xiàng)目文件夾下創(chuàng)建nginx配置文件mhwl_nginx.conf)
upstream django {
server unix:///root/mysite/mhwl/mhwl.sock; # for a file socket
#server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 81;
# the domain name it will serve for
server_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 5120M; # adjust to taste
location /static {
alias /root/mysite/mhwl/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /root/mysite/mhwl/uwsgi_params; # the uwsgi_params file you installed
}
}
創(chuàng)建mhwl_nginx.conf的軟鏈接享言,使其能夠?yàn)閚ginx所用,
sudo ln -s /root/mysite/mhwl/mhwl_nginx.conf /etc/nginx/sites-enabled/
啟動(dòng)nginx
sudo service nginx start
啟動(dòng)uwsgiuwsgi --ini /root/mysite/mhwl/uwsgi.ini
饼记,以上設(shè)置都正確的話(huà),訪(fǎng)問(wèn)http://localhost:81就可以看到頁(yè)面了如果有錯(cuò)誤凡橱,看頁(yè)面打印信息或者錯(cuò)誤日志 nginx錯(cuò)誤日志
/var/log/nginx/error.log
,uwsgi日志/root/mysite/mhwl/uwsgi.log
(此例中uwsgi.log所在的路徑是我指定的亭姥,具體的路徑還應(yīng)結(jié)合自身的情況)