Python 2.7 将http请求路由到WSGI应用程序(Flask+;Apache)
我的基于Flask的web应用已经准备就绪,我目前正在将其连接到Apache2.2 当我从根目录启动Apache服务应用程序时Python 2.7 将http请求路由到WSGI应用程序(Flask+;Apache),python-2.7,apache,mod-wsgi,wsgi,Python 2.7,Apache,Mod Wsgi,Wsgi,我的基于Flask的web应用已经准备就绪,我目前正在将其连接到Apache2.2 当我从根目录启动Apache服务应用程序时 WSGIScriptAlias / /var/www/path/to/script.wsgi 一切正常。但是,我希望为连接到不同数据库的多个版本的WSGI脚本提供服务,这意味着我需要为每个版本提供唯一的别名: WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi ... WSGIScriptAl
WSGIScriptAlias / /var/www/path/to/script.wsgi
一切正常。但是,我希望为连接到不同数据库的多个版本的WSGI脚本提供服务,这意味着我需要为每个版本提供唯一的别名:
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi
...
WSGIScriptAlias /secondscript /var/www/path/to/second/script.wsgi
当我尝试访问其中一个时:
www.example.com/firstscript
WSGI应用程序会加载,但所有http请求仍会路由到根目录。对我来说,将所有http请求重新路由到WSGI应用程序的最佳方式是什么?以下是我的apache配置:
WSGIPythonHome /usr
WSGIPythonPath /var/www/path/to/first
<VirtualHost *>
WSGIDaemonProcess firstscript user=apache group=apache threads=5 python-path=/lib/python2.7/site-packages
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi
<Directory /var/www/path/to/first>
WSGIProcessGroup %{GLOBAL}
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
WSGIPythonHome/usr
WSGIPythonPath/var/www/path/to/first
wsgidaemonprocessfirstscript user=apachegroup=apache threads=5 python path=/lib/python2.7/site-packages
WSGIScriptAlias/firstscript/var/www/path/to/first/script.wsgi
WSGIProcessGroup%{GLOBAL}
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
通融
编辑:
我遵循了@grahamdumpleton(非常感谢)的建议,这些建议帮助我清理了Apache配置,但我的http请求继续路由到Apache服务器的根目录,而不是WSGI应用程序。这是我当前的配置:
WSGIPythonHome /usr
WSGIPythonPath /var/www/path/to/first
<VirtualHost *>
WSGIDaemonProcess firstscript threads=5
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi process-group=firstscript application-group=%{GLOBAL}
<Directory /var/www/path/to/first>
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
WSGIPythonHome/usr
WSGIPythonPath/var/www/path/to/first
WSGIDaemonProcess firstscript线程=5
WSGIScriptAlias/firstscript/var/www/path/to/first/script.wsgi进程组=firstscript应用程序组=%{GLOBAL}
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
通融
我还尝试在目录标记下添加一个进程组:
WSGIProcessGroup firstscript
,但也没有产生任何影响。首先应删除以下内容:
WSGIProcessGroup %{GLOBAL}
这会导致所有内容都在同一个Python解释器中处理,甚至在守护进程组中也不处理,因此它们很可能相互干扰
使用:
python-path=/lib/python2.7/site-packages
这也是错误的。在使用系统Python时,您不需要这样做,Python path
无论如何都是引用虚拟环境的错误方式
最后,您不需要:
user=apache group=apache
或者默认为已经使用Apache用户
第一次更改可能足以让它工作,因为每个应用程序现在都将在守护进程进程组的一个单独的子解释器中运行
如果这不起作用,您应该创建多个守护进程组,并将每个进程组委托给单独的守护进程组
这将通过以下方式实现:
WSGIDaemonProcess firstscript threads=5
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi process-group=firstscript application-group=%{GLOBAL}
WSGIDaemonProcess secondscript threads=5
WSGIScriptAlias /secondscript /var/www/path/to/second/script.wsgi process-group=secondscript application-group=%{GLOBAL}
谢谢你的编辑!我已经做了您建议的更改,但我的http请求仍然路由到web服务器的根目录,而不是WSGI应用程序。我已经编辑了我的问题,所以你可以看到新的配置!您还有什么建议吗?这很像,因为您没有在主机名中添加
ServerName
指令。如果有先前的虚拟主机
,它将在无法基于主机名进行匹配时将其用作回退。另外,在使用系统Python时,不需要WSGIPythonHome
指令。而且,通常您会在VirtualHost
中使用*:80
,而不仅仅是*
。