Nginx+uwsgi+Django部署代碼怎么編寫,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供臺(tái)前網(wǎng)站建設(shè)、臺(tái)前做網(wǎng)站、臺(tái)前網(wǎng)站設(shè)計(jì)、臺(tái)前網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、臺(tái)前企業(yè)網(wǎng)站模板建站服務(wù),10多年臺(tái)前做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
在你的機(jī)器上寫一個(gè)test.py
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
然后執(zhí)行shell命令:
uwsgi --http :8001 --wsgi-file test.py
訪問網(wǎng)頁(yè):
http://127.0.0.1:8001/
看在網(wǎng)頁(yè)上是否有Hello World
[root@host-192-168-1-56 devops]# more my.ini
[uwsgi]
socket=:8001
chdir=/svn/devops/devops ###項(xiàng)目目錄
pythonapth=/usr/bin/python
processes=4
env=DJANGO_SETTINGS_MODULE=devops.settings ###指定 項(xiàng)目名.setting
module=devops.wsgi ###指定wsgi.py配置文件,該配置文件和setting在一個(gè)目錄下
threads=0
master=true
daemonize=/tmp/uwsgi.log
pidfile=/tmp/uwsgi.pid
python-autoreload=true
buffer-size=51200
[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()
配置文件
[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調(diào)用項(xiàng)目的靜態(tài)文件
expires 20d;
}
location / {
uwsgi_pass django; ---反向代理,簡(jiǎn)單寫法直接寫成uwsgi_pass 127.0.0.1:8001即可
include uwsgi_params;
}
access_log /home/wwwlogs/devops.log access;
}
啟動(dòng)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
測(cè)試:
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。