python - uwsgi+django的搭建問題
問題描述
各位大蝦好,小蝦效仿http://www.runoob.com/django/...搭建了一個nginx+uwsgi+django的環境。其中uwsgi已經成功了。
我寫了一個新的project叫logan,目錄就放在/django里,django也看到it works了。然后在/django/logan里寫了一個logan_wsgi.py ,如下
#!/usr/bin/env python# coding: utf-8import osimport sys# 將系統的編碼設置為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 //主進程vhost = true //多站模式no-site = true//多站模式時不設置入口模塊和文件workers = 2 //子進程數reload-mercy = 10vacuum = true //退出、重啟時清理文件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;}
然后我通過uwsgi --ini /etc/uwsgi9090.ini & 啟動uwsgi,然后又啟動了nginx。
現在瀏覽器上輸入 服務器外網地址 就會出現502 Bad gateway錯誤,然后打開uwsgi的日志,出現這樣:
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進程。然后在瀏覽器輸入外網地址之后,不再是502了,而是Internal Server Error。
打開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=’外網地址|’) (callable not found or import error)--- no python application found, check your startup logs for errors ---外網地址 [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單獨打開是不報錯的,如下:
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>>>
請問這樣我應該怎么辦?
問題解答
回答1:問題解決了,在uwsgi里使用了chdir 就好了
話說django的資料真的很少,而且他和python升級太快,很多資料的解答放在最新版本里已經不能用了。
回答2:from django.core.handlers.wsgi import WSGIHandler有問題這是老版本的寫法,改成from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()今天我也遇到這問題,希望能幫到你
相關文章:
1. javascript - 在 vue里面用import引入js文件,結果為undefined2. html - 爬蟲時出現“DNS lookup failed”,打開網頁卻沒問題,這是什么情況?3. 求教一個mysql建表分組索引問題4. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現5. html5 - input type=’file’ 上傳獲取的fileList對象怎么存儲于瀏覽器?6. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?7. python沒入門,請教一個問題8. php如何獲取訪問者路由器的mac地址9. node.js - 用nodejs 的node-xlsx模塊去讀取excel中的數據,可是讀取出來的日期是數字,請問該如何讀取日期呢?10. javascript - 我的站點貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?
