具體環(huán)境:
Ubuntu 14.04 Python 2.7.6 Django 1.7.1 Virtualenv name:test Nginx uwsgi
假設(shè) 項(xiàng)目文件夾位于 /data/www/ts 設(shè)置保存在 ./conf
django+uwsgi的部署實(shí)在是太蛋疼了..網(wǎng)上已有的教程似乎有新版本的兼容問題。最后跑到uwsgi官網(wǎng)上找的教程終于跑通了..
不過官網(wǎng)的教程似乎有引導(dǎo)教學(xué)性質(zhì),部署的時(shí)候就顯得很繞彎路,在這里記錄下來精簡內(nèi)容
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
首先,需要一個(gè)uwsgi_params文件,放在項(xiàng)目的conf文件夾里面。之后需要指向它。文件內(nèi)容如下:
創(chuàng)建一個(gè)叫做ts_nginx.conf 的文件,內(nèi)容如下
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name .example.com; # 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 /data/www/ts/media; # your Django project's media files - amend as required
}
location /static {
alias /data/www/ts/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 /data/www/ts/conf/uwsgi_params; # the uwsgi_params file you installed
}
}
把這個(gè)conf文件連接到nginx的搜索目錄里面。
先決條件:這里要設(shè)置好django項(xiàng)目的settings里面static files
python manage.py collectstatic
之后:
應(yīng)該就可以看到
http://example.cn:8000/media/1.gif
了(事先放進(jìn)去一個(gè)靜態(tài)文件)
之后的blabla步驟都是廢話,跳到這里:
ts_uwsgi.ini 在項(xiàng)目根目錄
這里環(huán)境變量設(shè)置env需要conf文件夾有init.py,否則conf不會(huì)被認(rèn)為是module
(目前除了80端口,其他端口都可以通過地址:端口訪問。已經(jīng)測(cè)試8000,81.80測(cè)試不知道為什么不成。明天待續(xù))
新聞熱點(diǎn)
疑難解答
圖片精選