与此类似: Deploying multiple django apps on Apache with mod_wsgi
我试图在mod_wsgi上托管两个django应用程序,但其中一个是root用户。即WSGI指令将是
WSGIScriptAlias / <path to django wsgi file for app1>
WSGIScriptAlias /app2 <path to django wsgi file for app2>
仅仅使用像这样的WSGIScript别名似乎不起作用。我尝试将它们放在位置指令中,但这也不起作用。有没有办法实现这个目标?
在Graham的回答之后,我尝试了这个:<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app2
WSGIScriptAlias /app2 /<path to app2 wsgi file>/
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app1
WSGIScriptAlias / /<path to app1 wsgi file>
</VirtualHost>
但不幸的是,对于site1.com/app2的请求仍然由django应用程序app1处理。我在配置中犯了错误吗?
答案 0 :(得分:2)
订单错误。使用:
WSGIScriptAlias /app2 <path to django wsgi file for app2>
WSGIScriptAlias / <path to django wsgi file for app1>
最深层嵌套必须是第一个,否则'/'将首先匹配并覆盖其他所有内容。
更新1
添加问题之后。现在使用:
<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
<Location /app2>
WSGIProcessGroup app2
</Location>
WSGIScriptAlias /app2 /<path to app2 wsgi file>/
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app1
WSGIScriptAlias / /<path to app1 wsgi file>
</VirtualHost>
您需要将WSGIProcessGroup
指令范围限定为子URL,以便只将该子URL的请求委托给mod_wsgi守护程序进程组。
上面的另一种写作方式是:
<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
WSGIScriptAlias /app2 /<path to app2 wsgi file>/ process-group=app2
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIScriptAlias / /<path to app1 wsgi file> process-group=app1
</VirtualHost>
换句话说,使用process-group
WSGIScriptAlias
选项来指示每个应该运行的位置。
当使用守护进程模式并且每个进程只有一个应用程序时,还建议添加:
WSGIApplicationGroup %{GLOBAL}
这迫使WSGI应用程序在各自的进程中使用主Python解释器上下文,避免了在没有正确实现某些带有C扩展的Python包以便使用Python子解释器时可能出现的问题。