Apache Virutalhost 子域指向同一目录
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道你是否解决过这个问题,但我遇到了同样的问题,结果我忘记更改 httpd.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:
taken from this tutorial which is priceless:
http://kevchapman.co.uk/development/setting-up-apache-on-snow-leopard/
我认为这是因为你使用
服务器别名 *.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