【问题标题】:Serving multiple Django projects in different virtualenv at the same IP (Apache)在同一 IP (Apache) 的不同 virtualenv 中为多个 Django 项目提供服务
【发布时间】:2018-06-09 10:31:29
【问题描述】:

我正在尝试在 Apache 上的同一 IP 地址的不同 virtualenv 上为两个 Django 项目提供服务。

我的第一个网站是http://myip/site-1 第二个:http://myip/site-2

当我运行 http://myip/site-1 时,Apache 会毫无问题地提供它,但是当我运行第二个 (http://myip/site-2) 时,它会引发以下问题:

The requested URL /site-2/ was not found on this server.

因为它在第一个站点的文档根目录中搜索。

这是我的 apache.conf

<VirtualHost *:80>
  ServerName site-1.example.com
  DocumentRoot /home/venv/site-1

 # adjust the following line to match your Python path 
 WSGIDaemonProcess site-1.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv/lib/python2.7
 WSGIProcessGroup site-1.example.com
 WSGIScriptAlias / /home/venv/site-1/site-1/wsgi.py

 <directory /home/venv/site-1>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /home/venv/site-1/static_root/

 <Directory /home/venv/site-1/static_root>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </Directory>

</VirtualHost>

<VirtualHost *:80>
  ServerName site-2.example.com
  DocumentRoot /home/venv_mob/site-2

  # adjust the following line to match your Python path 
  WSGIDaemonProcess site-2.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv_mob/lib/python2.7
  WSGIProcessGroup site-2.example.com
  WSGIScriptAlias / /home/venv_mob/site-2/site-2/wsgi.py

<directory /home/venv_mob/site-2>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /home/venv_mob/site-2/static_root/

<Directory /home/venv_mob/site-2/static_root>
  AllowOverride all
  Require all granted
  Options FollowSymlinks
 </Directory>

</VirtualHost>

我尝试了很多在网上找到的解决方案,但问题仍然存在。

有什么想法吗?

【问题讨论】:

    标签: python django virtualenv mod-wsgi wsgi


    【解决方案1】:

    您必须连接到http://site-1.example.com(使用您示例中的术语),而不是http://myip/site-1。还有http://site-2.example.com,而不是http://myip/site-2

    一般来说,您可以拥有需要配置 DNS 的 name-based virtual hosts(将 site-1.example.comsite-2.example.com 映射到您的 IP 地址),或者您可以使用 run different sites on different ports

    【讨论】:

    • 非常感谢。我修改了 apache.conf 以便第二个虚拟主机在 81 端口上侦听,它工作了!!
    猜你喜欢
    • 2015-08-15
    • 2015-01-31
    • 2021-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    相关资源
    最近更新 更多