1

所以我可能对这里发生的事情有一些基本的了解,但我无法让它发挥作用。我有两个 django 网站,我希望能够将它们都托管在同一个盒子上,都在端口 80 上。有什么魔法可以让它正常工作吗?这是我的站点可用/默认文件的样子:

<VirtualHost *:80>
    WSGIScriptAlias / /path/to/proj/apache/django.wsgi
    AliasMatch ^/([^/]*\.css) /path/to/proj/static/
    Alias /media /path/to/proj/static/
    Alias /static/ /path/to/proj/static/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    WSGIScriptAlias / /path/to/otherproj/apache/django.wsgi

    ErrorLog ${APACHE_LOG_DIR}/error2.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

显然,这是行不通的,因为导航到该站点会命中第一个站点,而它永远不会转到第二个站点。所以我的问题是,我如何设置它,以便我可以在端口 80 上托管 2 个网站。也许我可以像 localhost/site1 和 localhost/site2 那样做,但无论我尝试什么,我都可以似乎无法让它发挥作用。

我玩过 ServerName 属性,但我真的不明白它是如何工作的,设置它似乎并没有改变点击那台机器的 ip 只显示第一个网站,我不知道在哪里使用ServerName 影响任何东西。

任何建议,或者让我知道是否需要提供更多信息。

另请注意,如果我将第二个更改为端口 8080,它们都可以工作,但是这样做时,我似乎无法将域名放在 myip:8080 之上。

4

1 回答 1

1

我认为这里没有什么可以解释的。您只需要实际指定每个虚拟域的名称。

注意:不推荐使用 NameVirtualHost

<VirtualHost *:80>
    ServerName site1.ltd
    WSGIScriptAlias / /path/to/proj/apache/django.wsgi
    AliasMatch ^/([^/]*\.css) /path/to/proj/static/
    Alias /media /path/to/proj/static/
    Alias /static/ /path/to/proj/static/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName site2.ltd
    WSGIScriptAlias / /path/to/otherproj/apache/django.wsgi

    ErrorLog ${APACHE_LOG_DIR}/error2.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
于 2013-03-03T23:21:56.750 回答