Python 如何使用mod_wsgi在单个域下托管多个django项目?
我有多个django项目,我想在同一个域中托管它们 例如:Python 如何使用mod_wsgi在单个域下托管多个django项目?,python,django,apache,mod-wsgi,Python,Django,Apache,Mod Wsgi,我有多个django项目,我想在同一个域中托管它们 例如:example.com/oneexample.com/two 我已经搜索了各种解决方案,并找到了下面给出的链接,这对我很有帮助。 从上面的阅读中,我知道我需要mod_wsgi,但我很困惑,在哪里安装这个mod_wsgi——我需要在每个项目文件夹下安装(每个myenv单独安装)还是应该只安装一次。 请帮助我如何安装此mod_wsgi,以及如何在同一域名下托管多个项目。我将告诉您我们在项目中的做法。我们有一个Django项目,有不同的路线。
example.com/one
example.com/two
我已经搜索了各种解决方案,并找到了下面给出的链接,这对我很有帮助。
从上面的阅读中,我知道我需要mod_wsgi
,但我很困惑,在哪里安装这个mod_wsgi
——我需要在每个项目文件夹下安装(每个myenv单独安装)还是应该只安装一次。
请帮助我如何安装此mod_wsgi
,以及如何在同一域名下托管多个项目。我将告诉您我们在项目中的做法。我们有一个Django项目,有不同的路线。例如/players
,/tablet
。我们在两个Docker容器中托管了我们的项目。我们使用NGINX作为反向代理。NGINX根据路由将请求重定向到适当的容器。NGINX面向世界。但是,我不确定它是否对您有用。安装mod\u wsgi
取决于您的主机操作系统是什么。检查说明。如果您正在使用CentOS或RedHat,我建议您查看IUS社区;它们为Python 3.6和mod_wsgi
提供了一个包含yum可安装软件包的存储库。您安装的mod_wsgi
版本必须根据您在虚拟环境中运行的相同版本的Python进行编译
然后您需要正确配置VirtualHost
。如果在根目录中有一个主机,它必须在定义中位于最后。下面是一个例子:
<VirtualHost *:443>
TimeOut 300
SSLEngine On
ServerName mysite.example.com
# Set to the lobal Application Group
WSGIApplicationGroup %{GLOBAL}
# Pass Authorizations through to the WSGI app for Django REST Framework Token Auth
WSGIPassAuthorization On
WSGIDaemonProcess subsite-develop-https python-home=/web/subsite-develop/venv request-timeout=300 user=apache group=apache
WSGIProcessGroup subsite-develop-https
WSGIScriptAlias /subsite /web/subsite-develop/config/wsgi.py process-group=subsite-develop-https
<Directory /web/subsite-develop/config>
Require all granted
</Directory>
Alias /subsite/static/ /web/subsite-develop/static/
<Directory /web/subsite-develop/static>
Header always set Access-Control-Allow-Origin "*"
Require all granted
</Directory>
WSGIDaemonProcess django-mysite-develop-https python-home=/web/django-mysite-develop/venv request-timeout=300 user=apache group=apache
WSGIProcessGroup django-mysite-develop-https
WSGIScriptAlias / /web/django-mysite-develop/config/wsgi.py process-group=django-mysite-develop-https
<Directory /web/django-mysite-develop/config>
Require all granted
</Directory>
Alias /static/ /web/django-mysite-develop/static/
<Directory /web/django-mysite-develop/static>
Header always set Access-Control-Allow-Origin "*"
Require all granted
</Directory>
Alias /media/ /var/media/mysite-www/
<Directory /var/media/mysite-www>
Require all granted
</Directory>
</VirtualHost>
超时300
斯伦金安
ServerName mysite.example.com
#设置为全局应用程序组
WSGIApplicationGroup%{GLOBAL}
#将授权传递给Django REST Framework令牌身份验证的WSGI应用程序
WSGIPassAuthorization On
WSGIDaemonProcess subsite develope https python home=/web/subsite develope/venv request timeout=300 user=apache group=apache
WSGIProcessGroup子网站开发https
WSGIScriptAlias/subsite/web/subsite develope/config/wsgi.py进程组=subsite develope https
要求所有授权
别名/subsite/static//web/subsite-develop/static/
标题始终设置访问控制允许原点“*”
要求所有授权
WSGIDaemonProcess django mysite develope https python home=/web/django mysite develope/venv request timeout=300 user=apache group=apache
WSGIProcessGroup django mysite开发https
WSGIScriptAlias//web/django mysite develope/config/wsgi.py进程组=django mysite develope https
要求所有授权
别名/static//web/django mysite开发/static/
标题始终设置访问控制允许原点“*”
要求所有授权
别名/media//var/media/mysite www/
要求所有授权
此示例将在/subsite/
上托管一个站点,在根目录/
上托管另一个站点。请注意,根站点位于最后。这还意味着您将无法在根项目中使用路由/subsite/
,因为Apache将通过WSGIScriptAlias
定义将其转移到
这也适用于具有TLS的现场;如果不使用TLS,您可能必须将443
切换到80
,并删除SSLEngine On
。WSGIPassAuthorization
是针对Django REST框架令牌的,您可能也可以删除它,但我将其留给了一个更完整的示例。这是针对Apache2.4+,当他们切换到Require-all-grated
语法时
IUS社区,如果在RedHat/CentOS上:首先,mod_wsgi与在单个域中托管多个项目无关。其次,如果您确实想使用它为您的项目提供服务,请按照它的安装说明进行操作;什么是不清楚的?我刚才说的是我已经浏览了很多次,之后我开始了解mod_wsgi在一台主机上托管多个项目的方法。我也读过安装mod_wsgi的方法,现在我知道如何安装,但问题是在哪里安装它,因为我为每个项目创建了单独的虚拟环境。所以我需要在每个虚拟环境中安装它。正如我所说,您阅读了说明。mod_wsgi是为Apache安装的,它与虚拟环境无关。您好,谢谢您的回复,但我完全是一个初学者,真的不知道如何使用docker容器和Nginx。换句话说,我们运行两台服务器,每条路由一台。我们运行另一台服务器(NGINX),它将根据路由决定上述两台服务器。你到底想在哪里主持?你遵循多少层?谢谢,我现在理解这个概念了。我会这样做的。