uwsgi 和 apache2 问题

uwsgi and apache2 issue

我在设置 apache2 后面的 uwsgi 时遇到了问题。 这是我的系统:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:        12.04
Codename:       precise

$ apache2 -v
Server version: Apache/2.4.20 (Ubuntu)

$ uwsgi --version
2.0.14

$ cat /etc/init/uwsgi.conf 
description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/ --logto /var/log/uwsgi.log

$ python --version
Python 2.7.3

$ cat ~/myapp/wsgi.py
def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ["<h1 style='color:blue'>Hello There!</h1>"]

$ cd ~/myapp
$ uwsgi --socket 0.0.0.0:8081 --protocol=http -w wsgi

我可以浏览到 http://example.com:8081 并查看 "Hello there!" 测试页。所以,我假设 uwsgi 工作正常。但是,我想把 uwsgi 放在 apache2 后面,但是每当我尝试

$ a2enmod uwsgi

并重新启动 apache2 我收到一个我无法理解的错误:

$ service apache2 restart
* Restarting Apache httpd web server apache2                    [fail] 
* The apache2 configtest failed.
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf:
Syntax error on line 1 of /etc/apache2/mods-enabled/uwsgi.load:
Cannot load /usr/lib/apache2/modules/mod_uwsgi.so into server:
/usr/lib/apache2/modules/mod_uwsgi.so: cannot open shared object file:
No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.

谁能帮我解决这个问题?我已经搜索了几个小时,但找不到对我有帮助的任何东西..

非常感谢您。

PS: 哦,我在 apache 错误日志中找不到任何相关信息。

万一有人感兴趣,下面是我如何让它工作的:

我没有使用 uwsgi_mod,而是代理了我的 apache 配置中的所有内容:

<VirtualHost *:80>
  ...
  ProxyPreserveHost On
  ProxyRequests Off
  ProxyVia Off
  ProxyPass / http://127.0.0.1:8081/
  ProxyPassReverse / http://127.0.0.1:8081/
</VirtualHost>

uwsgi 命令将 运行 与 uwsgi --ini uwsgi.ini 其中 uwsgi.ini 将包含以下行

[uwsgi]
chdir = path/to/my/project
http-socket = :8081
module = wsgi:application
...

这样我就不需要 运行 uwsgi_mod 并且一切正常。希望有一天能对任何人有所帮助。