Nginx+uwsgi+Django部署代码怎么编写-创新互联
Nginx+uwsgi+Django部署代码怎么编写,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
创新互联是一家成都网站设计、网站制作,提供网页设计,网站设计,网站制作,建网站,按需制作,网站开发公司,于2013年开始是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。Nginx+uwsgi+Django部署代码
安装uwsgi
1.安装pip
2.安装uwsgi
3 测试uwsgi
在你的机器上写一个test.py
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
然后执行shell命令:
uwsgi --http :8001 --wsgi-file test.py
访问网页:
http://127.0.0.1:8001/
看在网页上是否有Hello World
4.编写uwsgi启动配置文件
[root@host-192-168-1-56 devops]# more my.ini
[uwsgi]
socket=:8001
chdir=/svn/devops/devops ###项目目录
pythonapth=/usr/bin/python
processes=4
env=DJANGO_SETTINGS_MODULE=devops.settings ###指定 项目名.setting
module=devops.wsgi ###指定wsgi.py配置文件,该配置文件和setting在一个目录下
threads=0
master=true
daemonize=/tmp/uwsgi.log
pidfile=/tmp/uwsgi.pid
python-autoreload=true
buffer-size=51200
5.编写wsgi配置文件
[root@host-192-168-1-56 devops]# more devops/wsgi.py
"""
WSGI config for devops project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "devops.settings")
application = get_wsgi_application()
6.配置nginx
配置文件
[root@host-192-168-1-56 devops]# more /usr/local/nginx/conf/vhost/blog.haodai.com.conf
upstream django {
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 8099;
server_name devops.XXX.net;
charset utf-8;
root /svn/devops/devops;
client_max_body_size 75M; # adjust to taste
location /static {
alias /svn/devops/devops/static; ---nginx调用项目的静态文件
expires 20d;
}
location / {
uwsgi_pass django; ---反向代理,简单写法直接写成uwsgi_pass 127.0.0.1:8001即可
include uwsgi_params;
}
access_log /home/wwwlogs/devops.log access;
}
配置文件
[root@host-192-168-1-56 devops]# more /usr/local/nginx/conf/vhost/blog.haodai.com.conf
upstream django {
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 8099;
server_name devops.XXX.net;
charset utf-8;
root /svn/devops/devops;
client_max_body_size 75M; # adjust to taste
location /static {
alias /svn/devops/devops/static; ---nginx调用项目的静态文件
expires 20d;
}
location / {
uwsgi_pass django; ---反向代理,简单写法直接写成uwsgi_pass 127.0.0.1:8001即可
include uwsgi_params;
}
access_log /home/wwwlogs/devops.log access;
}
7 启动,测试
启动uwsgi和nginx
[root@host-192-168-1-56 devops]# /usr/local/python/bin/uwsgi my.ini
[root@host-192-168-1-56 devops]# nginx -s reload
测试:
启动uwsgi和nginx
[root@host-192-168-1-56 devops]# /usr/local/python/bin/uwsgi my.ini
[root@host-192-168-1-56 devops]# nginx -s reload
测试:
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联-成都网站建设公司行业资讯频道,感谢您对创新互联的支持。
文章标题:Nginx+uwsgi+Django部署代码怎么编写-创新互联
标题URL:http://azwzsj.com/article/djcjdp.html