Multiple domain with the same ip and port in apach

2019-02-15 13:08发布

问题:

I want to bind two different domain in my VPS with the same ip and port, here is my httpd.conf:

<VirtualHost 106.187.96.123:80>
    DocumentRoot /home/roy/sobuhu
    ServerName aaa.com
</VirtualHost>

<VirtualHost 106.187.96.123:80>
    DocumentRoot /disk1/allen/www
    ServerName bbb.com
</VirtualHost>

<VirtualHost 106.187.96.123:80>
    DocumentRoot /disk1/allen/www
    ServerName www.bbb.com
</VirtualHost>

Can I config the ServerName use syntax like *.bbb.com ? so I can access www.bbb.com、bbs.bbb.com with the DocumentRoot /disk1/allen/www.

Now I visit bbs.bbb.com, it will turn to /home/roy/sobuhu.

回答1:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /home/roy/sobuhu
    ServerName aaa.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /disk1/allen/www
    ServerName bbb.com
    ServerAlias *.bbb.com
</VirtualHost>