时间: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邮箱联系删除。
如何在生产上部署Django?Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式。uwsgi介绍uWSGI是一个
如何在生产上部署Django?Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式。uwsgi介绍uWSGI是一个
本文实例讲述了uwsgi+nginx部署Django项目操作。分享给大家供大家参考,具体如下:uWSGI概述uWSGI是一个全功能的HTTP服务器,可以把HTT
之前面我们使用uwsgi部署项目比较繁琐,本章节介绍使用pm2+nginx一键部署django项目PM2的主要特性:内建负载均衡(使用Nodecluster集群
举个例子吧Django最佳实践与部署:Nginx+Gunicorn+Supervisor(Ubuntu和CentOS)http://sfdye.com/arti