APACHE2如何里一个站点绑定多个域名?用ServerAlias
以前很笨,要使多个域名指向同一站点总是这样写:
<VirtualHost *:80>
ServerAdmin i@kuigg.com
DocumentRoot /www/kuigg.com
ServerName kuigg.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin i@kuigg.com
DocumentRoot /www/kuigg.com
ServerName www.kuigg.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin i@kuigg.com
DocumentRoot /www/kuigg.com
ServerName abc.kuigg.com
</VirtualHost>
这样一来就等于绑了多少域名就开了多少虚拟主机…………
后来看了看书,发现有个叫”ServerAlias“的东西可以用
其实可以这样:
<VirtualHost *:80>
ServerAdmin i@kuigg.com
DocumentRoot /www/kuigg.com
ServerName kuigg.com
ServerAlias www.kuigg.com abc.kuigg.com
</VirtualHost>
要绑多少个域名都可以写在 ServerAlias 后面,用空格隔开即可
apache AH01630: client denied by server configuration错误解决方法
出现这个错误的原因是,apache2.4 与 apache2.2 的虚拟主机配置写法不同导致。
apache2.2的写法:
<VirtualHost *:80>
ServerName fdipzone.demo.com
DocumentRoot "/home/fdipzone/sites/www"
DirectoryIndex index.html index.php
<Directory "/home/fdipzone/sites/www">
Options -Indexes +FollowSymlinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
如果在2.4中使用以上写法就会有apache AH01630: client denied by server configuration错误。
解决方法,apache2.4中
- Order deny,allow
- Allow from all
- Allow from host ip
- Require all granted
- Require host ip
修改后的配置如下:
- <VirtualHost *:80>
- ServerName fdipzone.demo.com
- DocumentRoot "/home/fdipzone/sites/www"
- DirectoryIndex index.html index.php
- <Directory "/home/fdipzone/sites/www">
- Options -Indexes +FollowSymlinks
- AllowOverride All
- Require all granted
- </Directory>
- </VirtualHost>