国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - uwsgi+django的搭建問(wèn)題

瀏覽:199日期:2022-08-25 11:09:15

問(wèn)題描述

各位大蝦好,小蝦效仿http://www.runoob.com/django/...搭建了一個(gè)nginx+uwsgi+django的環(huán)境。其中uwsgi已經(jīng)成功了。

我寫了一個(gè)新的project叫l(wèi)ogan,目錄就放在/django里,django也看到it works了。然后在/django/logan里寫了一個(gè)logan_wsgi.py ,如下

#!/usr/bin/env python# coding: utf-8import osimport sys# 將系統(tǒng)的編碼設(shè)置為UTF8reload(sys)sys.setdefaultencoding(’utf8’)os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'logan.settings')from django.core.handlers.wsgi import WSGIHandlerapplication = WSGIHandler()

我修改了一下uwsgi9090.ini,詳情如下:

[uwsgi]socket = 127.0.0.1:9090master = true //主進(jìn)程vhost = true //多站模式no-site = true//多站模式時(shí)不設(shè)置入口模塊和文件workers = 2 //子進(jìn)程數(shù)reload-mercy = 10vacuum = true //退出、重啟時(shí)清理文件max-requests = 1000limit-as = 512buffer-size = 30000pidfile = /var/run/uwsgi9090.piddaemonize = /website/uwsgi9090.log

然后我的nginx.conf詳情如下:

server {listen 80;server_name localhost;location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9090; uwsgi_param UWSGI_SCRIPT logan_wsgi.py; uwsgi_param UWSGI_CHDIR /django/logan; index index.html index.htm; client_max_body_size 35m;}

然后我通過(guò)uwsgi --ini /etc/uwsgi9090.ini & 啟動(dòng)uwsgi,然后又啟動(dòng)了nginx。

現(xiàn)在瀏覽器上輸入 服務(wù)器外網(wǎng)地址 就會(huì)出現(xiàn)502 Bad gateway錯(cuò)誤,然后打開(kāi)uwsgi的日志,出現(xiàn)這樣:

your mercy for graceful operations on workers is 60 secondsmapped 296016 bytes (289 KB) for 2 cores*** Operational MODE: preforking ****** no app loaded. going in full dynamic mode ****** uWSGI is running in multiple interpreter mode ***spawned uWSGI master process (pid: 3868)spawned uWSGI worker 1 (pid: 3869, cores: 1)spawned uWSGI worker 2 (pid: 3870, cores: 1)-- unavailable modifier requested: 0 ---- unavailable modifier requested: 0 ---- unavailable modifier requested: 0 ---- unavailable modifier requested: 0 ---- unavailable modifier requested: 0 --

我就yum install uwsgi-plugin-python,用uwsgi --plugin python --ini /etc/uwsgi9090.ini & 重啟了uwsgi進(jìn)程。然后在瀏覽器輸入外網(wǎng)地址之后,不再是502了,而是Internal Server Error。

打開(kāi)uwsgi的日志一看是:

Traceback (most recent call last): File './logan_wsgi.py', line 13, in <module>

from django.core.handlers.wsgi import WSGIHandler

ImportError: No module named django.core.handlers.wsgiunable to load app 0 (mountpoint=’外網(wǎng)地址|’) (callable not found or import error)--- no python application found, check your startup logs for errors ---外網(wǎng)地址 [pid: 4282|app: -1|req: -1/12] 60.191.94.120 () {46 vars in 763 bytes} [Wed Mar 8 17:06:31 2017] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

但是我用python單獨(dú)打開(kāi)是不報(bào)錯(cuò)的,如下:

Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2Type 'help', 'copyright', 'credits' or 'license' for more information.>>> from django.core.handlers.wsgi import WSGIHandler>>>

請(qǐng)問(wèn)這樣我應(yīng)該怎么辦?

問(wèn)題解答

回答1:

問(wèn)題解決了,在uwsgi里使用了chdir 就好了

話說(shuō)django的資料真的很少,而且他和python升級(jí)太快,很多資料的解答放在最新版本里已經(jīng)不能用了。

回答2:

from django.core.handlers.wsgi import WSGIHandler有問(wèn)題這是老版本的寫法,改成from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()今天我也遇到這問(wèn)題,希望能幫到你

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 新乐市| 射阳县| 霞浦县| 桓台县| 铁岭县| 长汀县| 资兴市| 邵武市| 仙居县| 垦利县| 景泰县| 东海县| 怀柔区| 双流县| 湖南省| 鱼台县| 浦城县| 曲阜市| 河北省| 陇西县| 通榆县| 江川县| 铁力市| 湾仔区| 建平县| 赫章县| 台北县| 宿州市| 翼城县| 江北区| 寿阳县| 安龙县| 福鼎市| 临猗县| 密云县| 白沙| 庆元县| 闽侯县| 修武县| 苍山县| 涿鹿县|