简体   繁体   English

在端口80上托管多个网站

[英]Host multiple web sites on port 80

So I may be missing a bit of a fundamental understanding on what's going on here, but I cannot get this to work. 因此,我可能对这里发生的事情缺少一些基本的了解,但是我无法使它起作用。 I have two django websites, and I want to be able to host them both on the same box, both on port 80. Is there some magic to get this to work properly? 我有两个django网站,我希望能够将它们都托管在同一个盒子上,都在端口80上。是否有使它正常工作的魔力? Here's what my sites-available/default file looks like: 这是我的网站可用/默认文件如下所示:

<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>

Obviously this doesn't work since navigating to the site hits the first one and it never goes to the second one. 显然,这是行不通的,因为导航到该站点会遇到第一个站点,而永远不会到达第二个站点。 So my question is, how do I set this up so I can host 2 web sites on port 80. Perhaps I could do like localhost/site1 and localhost/site2 and figure it out that way, but no matter what I try I can't seem to get that to work. 所以我的问题是,如何设置它以便可以在端口80上托管2个网站。也许我可以像localhost / site1和localhost / site2那样进行处理,但无论如何我都可以似乎无法解决这个问题。

I have played with the ServerName property, but I don't really understand how that can work, setting it doesn't seem to change that hitting the ip of that machine only shows the first website, and I don't know where using the ServerName affects anything. 我已经使用过ServerName属性,但是我不太了解它是如何工作的,设置它似乎并没有改变点击那台计算机的ip仅显示第一个网站,并且我不知道在哪里使用ServerName会影响任何事情。

Any suggestions, or let me know if I need to give more information. 有任何建议,或者让我知道是否需要提供更多信息。

Also note they both work if I change the second one to port 8080, but when doing that I can't seem to put a domain name on top of myip:8080. 还要注意,如果我将第二个更改为端口8080,它们都可以工作,但是这样做时,似乎无法在myip:8080上放一个域名。

I don't think there is anything to explain here. 我认为这里没有什么要解释的。 You just need to actually specify the name of each virtual domain. 您只需要实际指定每个虚拟域的名称即可。

Note: NameVirtualHost is deprecated 注意: 不建议使用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM