APACHE利用ServerAlias servername实现一个站点绑定多个域名?

2021-07-09 10:33:05 浏览数 (1)

APACHE2如何里一个站点绑定多个域名?用ServerAlias 以前很笨,要使多个域名指向同一站点总是这样写:

代码语言:javascript复制
<VirtualHost *:80>
    ServerAdmin webmaster@admin
    DocumentRoot "D:/coreamp/htdocs/"
    ServerName localhost
    ErrorLog "../apache-2.2.16-project2-error.log"
    CustomLog "../apache-2.2.16-project2-access.log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@admin
    DocumentRoot "D:/coreamp/htdocs/"
    ServerName 127.0.0.1
    ErrorLog "../apache-2.2.16-project2-error.log"
    CustomLog "../apache-2.2.16-project2-access.log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@admin
    DocumentRoot "D:/coreamp/htdocs/"
    ServerName 192.168.8.133
    ErrorLog "../apache-2.2.16-project2-error.log"
    CustomLog "../apache-2.2.16-project2-access.log" common
</VirtualHost>

这样一来就等于绑了多少域名就开了多少虚拟主机………… 后来发现有个叫”ServerAlias“的东西可以用 其实可以这样:

代码语言:javascript复制
<VirtualHost *:80>
    ServerAdmin webmaster@admin
    DocumentRoot "D:/coreamp/htdocs/"
    ServerName localhost
    ServerAlias 127.0.0.1 192.168.8.133
    ErrorLog "../apache-2.2.16-project2-error.log"
    CustomLog "../apache-2.2.16-project2-access.log" common
</VirtualHost>

要绑多少个域名都可以写在 ServerAlias 后面,用空格隔开即可

0 人点赞