在Ubuntu 14.04上使用Apache2和mod_wsgi提供Django 1.8应用程序时出错

时间:2015-08-03 09:34:42

标签: python linux django apache ubuntu

我正在尝试使用Apache2和mod_wsgi为我的django项目提供服务而且我被困住了。一切正常,直到我尝试集成mod_wsgi。我正在使用python 3.相关编码如下:

Apache2.conf

<VirtualHost *:80>
        ServerAdmin myemail@example.com
        ServerName example.com
        ServerAlias www.example.com

        DocumentRoot /var/www/mysite

        Alias /static/ /var/www/mysite/static/

        <Directory /var/www/mysite/static>
        Require all granted
        </Directory>


        WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py


        <Directory /var/www/mysite/mysite/wsgi.py>
        <Files wsgi.py>
        Require all granted
        </Files>
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

错误日志

[Mon Aug 03 18:45:42.192589 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Mon Aug 03 18:45:42.192606 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Mon Aug 03 18:45:42.192623 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
[Mon Aug 03 18:45:42.192649 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084] ImportError: No module named 'mysite'

我知道它与如何在apache2.conf文件中配置wsgi有关,但不知道如何修复它。任何帮助,将不胜感激。 感谢

1 个答案:

答案 0 :(得分:3)

您需要添加以下内容:

WSGIPythonPath /var/www/mysite

doc“WSGIPythonPath行确保您的项目包可以在Python路径上导入;换句话说,导入mysite可以工作。”