centos - apache設定django報錯:cannot be loaded as Python modules
怪我咯
怪我咯 2017-04-25 09:01:21
0
2
861

平台:Centos5 ECS上的
django版本1.6
apache版本2.2
透過mod_wsgi將django專案配置到apache上一直沒有成功,單獨測試wsgi可以訪問,django單獨跑runserver也可以跑通
專案路徑:

/var/www/html `-- mysite |-- manage.py |-- mysite | |-- __init__.py | |-- __init__.pyc | |-- media | |-- settings.py | |-- settings.pyc | |-- static | |-- urls.py | |-- wsgi.py | `-- wsgi.pyc `-- wsgi `-- django.wsgi

透過startproject創建的項目,單獨runserver可以跑通,新增了wsgi資料夾以及django.wsgi設定檔

httpd.conf檔案中新增了:

LoadModule wsgi_module modules/mod_wsgi.so  ServerAdmin root@localhost DocumentRoot /var/www/html ServerName 121.40.202.235 ErrorLog "logs/error_log" CustomLog "logs/access_log" common WSGIScriptAlias / /var/www/html/mysite/wsgi/django.wsgi  Order deny,allow Allow from all  

django.wsgi檔:

import os import sys import django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE']= 'mysite.settings' sys.path.append('/usr/local/lib/python2.7/site/packages') app_path = os.path.dirname(__file__) if app_path not in sys.path: sys.path.append(app_path) application =django.core.handlers.wsgi.WSGIHandler()

重啟apache伺服器沒有問題,存取網址後報錯日誌為:

[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] mod_wsgi (pid=18776): Target WSGI script '/var/www/html/mysite/wsgi/django.wsgi' cannot be loaded as Python module. [Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] mod_wsgi (pid=18776): Exception occurred processing WSGI script '/var/www/html/mysite/wsgi/django.wsgi'. [Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] Traceback (most recent call last): [Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] File "/var/www/html/mysite/wsgi/django.wsgi", line 3, in ? [Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] import django.core.handlers.wsgi [Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] ImportError: No module named django.core.handlers.wsgi
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回覆 (2)
我想大声告诉你

不需要django.wsgi這個文件,把WSGIScriptAlias 指向mysite/wsgi.py

    滿天的星座

    搞uwsgi,so的搞法完全是PHP的玩法,不夠Nice。

      最新下載
      更多>
      網站特效
      網站源碼
      網站素材
      前端模板
      關於我們 免責聲明 Sitemap
      PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!