Apache Virutalhost 子域指向同一目录

发布于 2024-10-07 06:32:25 字数 2487 浏览 3 评论 0原文

hello,

我有两个虚拟主机子域指向不同的目录,但是当我在浏览器中加载这两个子域时,我让它们都指向同一目录。这是我的 vhost.conf

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName subdomain1.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain1/path/to/directory/trunk/error.log
        CustomLog /subomain1/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName subdomain1.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain1.crt
        SSLCertificateKeyFile /ssl/private/subdomain1.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

 <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName subdomain2.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain2/path/to/directory/trunk/error.log
        CustomLog /subomain2/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName subdomain2.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain2.crt
        SSLCertificateKeyFile /ssl/private/subdomain2.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

我已经尝试过谷歌,但没有一个答案似乎有帮助。

我正在使用 ubuntu 服务器,

非常感谢

elloo,

i have two virtualhost subdomains point to different directories however when i load both subdomains in the browser, i get them both pointing to same directory. here is my vhost.conf

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName subdomain1.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain1/path/to/directory/trunk/error.log
        CustomLog /subomain1/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName subdomain1.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain1.crt
        SSLCertificateKeyFile /ssl/private/subdomain1.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

 <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName subdomain2.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain2/path/to/directory/trunk/error.log
        CustomLog /subomain2/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName subdomain2.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain2.crt
        SSLCertificateKeyFile /ssl/private/subdomain2.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

i have tried google however none of the answers seems to help.

i'm using ubuntu server

many thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤凫 2024-10-14 06:32:25

不知道你是否解决过这个问题,但我遇到了同样的问题,结果我忘记更改 httpd.conf 文件,如下所示:

打开“httpd.conf”并取消注释行#461(大约),其中显示“Include /private/etc/apache2/extra/httpd-vhosts.conf”,然后保存。

摘自本教程,这是无价的:
http://kevchapman.co.uk/development/setting- up-apache-on-snow-leopard/

don't know if you ever solved this, but i was having the same problem and it turned out i forgot to change the httpd.conf file like this:

Open the “httpd.conf” and uncomment line #461 (approx) which reads “Include /private/etc/apache2/extra/httpd-vhosts.conf”, then save.

taken from this tutorial which is priceless:
http://kevchapman.co.uk/development/setting-up-apache-on-snow-leopard/

沩ん囻菔务 2024-10-14 06:32:25

我认为这是因为你使用
服务器别名 *.domain.com
在两个虚拟主机上,

因为 ServerAlias 指令指示列出的名称是人们可以用来查看同一网站的其他名称:

ServerAlias *.subdomain.com

那么对 subdomain.com 域中的所有主机的请求将由 subdomain1 提供服务.domain.com 虚拟主机。

这可能会有所帮助 http://httpd.apache.org/docs/2.0/ vhosts/name-based.html

I think its because youre using
ServerAlias *.domain.com
on both virtual hosts

since the ServerAlias directive indicates that the listed names are other names which people can use to see that same web site:

ServerAlias *.subdomain.com

then requests for all hosts in the subdomain.com domain will be served by the subdomain1.domain.com virtual host.

this might help http://httpd.apache.org/docs/2.0/vhosts/name-based.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文