不正确的配置:导入中间件时出错 - Django wsgi错误Apache

时间:2016-03-21 11:27:54

标签: python linux django apache

我的一个AWS Linux Server中有一个Python Django站点。首先,让我告诉你我在服务器上托管我的Django应用程序所做的工作。默认情况下,服务器已安装Python 2.6.9。对于我的应用程序,我已经在不同的位置(/opt/python2.7.6)编译和安装了Python 2.7.6。不过,默认的python是2.6.9。我的应用程序位于一个虚拟环境下,该环境是针对这个新安装的Python(2.7.6)创建的。我的Web服务器是Apache2(版本2.4),并使用以下命令通过编译Python 2.7.6来安装WSGI模块。

./ configure --with-python = / opt / python2.7.6 / bin / python

我已经相应地配置了apache,我收到以下错误。请告诉我如何解决这个问题。

[Mon Mar 21 10:38:32.669216 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Create interpreter 'www.example.com|'.
[Mon Mar 21 10:38:32.671113 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/example.com' to path.
[Mon Mar 21 10:38:32.671607 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/venv/lib/python2.7/site-packages' to path.
[Mon Mar 21 10:38:32.672621 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/example.com/example' to path.
[Mon Mar 21 10:38:32.681871 2016] [:info] [pid 26256] [client x.x.x.x:46626] mod_wsgi (pid=26256, process='www.example.com', application='www.example.com|'): Loading WSGI script '/home/testuser/example.com/example/wsgi.py'.
[Mon Mar 21 06:38:33.341024 2016] [:error] [pid 26256] [client x.x.x.x:46626] mod_wsgi (pid=26256): Exception occurred processing WSGI script '/home/testuser/example.com/example/wsgi.py'.
[Mon Mar 21 06:38:33.341297 2016] [:error] [pid 26256] [client x.x.x.x:46626] Traceback (most recent call last):
[Mon Mar 21 06:38:33.341478 2016] [:error] [pid 26256] [client x.x.x.x:46626]   File "/home/testuser/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Mon Mar 21 06:38:33.341772 2016] [:error] [pid 26256] [client x.x.x.x:46626]     self.load_middleware()
[Mon Mar 21 06:38:33.341926 2016] [:error] [pid 26256] [client x.x.x.x:46626]   File "/home/testuser/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware
[Mon Mar 21 06:38:33.342238 2016] [:error] [pid 26256] [client x.x.x.x:46626]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Mon Mar 21 06:38:33.342400 2016] [:error] [pid 26256] [client x.x.x.x:46626] ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "/home/testuser/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: PyUnicodeUCS2_AsUTF8String"

我已经尝试了许多方法来解决谷歌建议中的这个问题,但还没有工作。

以下是我的apache conf文件。

<VirtualHost  *:80>
ServerName www.example.com

DocumentRoot /home/testuser/example.com
LogLevel info
ErrorLog /home/testuser/http_error.log
CustomLog /home/testuser/http_access.log combined

WSGIDaemonProcess www.example.com processes=2 threads=15 display-name=%{GROUP} python-path=/home/testuser/example.com:/home/testuser/venv/lib/python2.7/site-packages
WSGIProcessGroup www.example.com

WSGIScriptAlias / /home/testuser/example.com/example/wsgi.py
Alias /media /home/testuser/site_assets/media
Alias /static /home/testuser/example.com/.static_built
<Directory /home/testuser/example.com/example>
    <Files wsgi.py>
        Order allow,deny
        Allow from all
    </Files>
</Directory>
</VirtualHost>

请注意,该网站与独立的python runserver命令配合良好。

如果您需要任何其他详细信息,请与我们联系。

谢谢,

1 个答案:

答案 0 :(得分:0)

我解决了。我在我的服务器上运行了三个Python版本(2.7.6,2.6.9和2.7.10),但默认情况下它是2.6.9。即使我的python虚拟环境是针对2.7.6,Apache也没有为我的应用程序选择那个python。我不知道为什么会这样。当我添加** WSGIPythonHome *作为指向我的虚拟环境python时,在我的apache配置文件的顶部它完美地工作。请参阅下面更新的apache配置文件。

WSGIPythonHome /home/testuser/venv
<VirtualHost  *:80>
ServerName www.example.com

DocumentRoot /home/testuser/example.com
LogLevel info
ErrorLog /home/testuser/http_error.log
CustomLog /home/testuser/http_access.log combined

WSGIDaemonProcess www.example.com processes=2 threads=15 display-name=%{GROUP} python-path=/home/testuser/example.com:/home/testuser/venv/lib/python2.7/site-packages
WSGIProcessGroup www.example.com

WSGIScriptAlias / /home/testuser/example.com/example/wsgi.py
Alias /media /home/testuser/site_assets/media
Alias /static /home/testuser/example.com/.static_built
<Directory /home/testuser/example.com/example>
    <Files wsgi.py>
        Order allow,deny
        Allow from all
    </Files>
</Directory> 
</VirtualHost>