Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程

时间:2021-05-22

具体环境:
Ubuntu 14.04 Python 2.7.6 Django 1.7.1 Virtualenv name:test Nginx uwsgi

假设 项目文件夹位于 /data/; # 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
}
}

把这个conf文件连接到nginx的搜索目录里面。

复制代码 代码如下:
sudo ln -s /data/www/ts/conf/ts_nginx.conf /etc/nginx/sites-enabled/

先决条件:这里要设置好django项目的settings里面static files

复制代码 代码如下:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
and then run

python manage.py collectstatic

之后:

复制代码 代码如下:
service nginx restart

应该就可以看到
http://example.cn:8000/media/1.gif
了(事先放进去一个静态文件)

之后的blabla步骤都是废话,跳到这里:

复制代码 代码如下:
Configuring uWSGI to run with a .ini file

ts_uwsgi.ini 在项目根目录

复制代码 代码如下:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /data/www/ts
# Django's wsgi file
module = ts.wsgi
# the virtualenv (full path)
home = /root/.envs/test
# 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:8001
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
# set an environment variable
env = DJANGO_SETTINGS_MODULE=conf.settings
uwsgi --ini mysite_uwsgi.ini # the --ini option is used to specify a file

这里环境变量设置env需要conf文件夹有init.py,否则conf不会被认为是module

(目前除了80端口,其他端口都可以通过地址:端口访问。已经测试8000,81.80测试不知道为什么不成。明天待续)

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章