Nginx+uwsgi+Django部署代码怎么编写
Nginx+uwsgi+Django部署代码怎么编写,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
创新互联建站专业为企业提供台前网站建设、台前做网站、台前网站设计、台前网站制作等企业网站建设、网页设计与制作、台前企业网站模板建站服务,10多年台前做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
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部署代码怎么编写
网站地址:http://myzitong.com/article/jcejpg.html