Apache VirtualHost(二级域名&多站点)

Apache的VirtualHost就是在一台机器上实现多个域名(包括二级域名)

配置可以写在/etc/httpd/conf/httpd.conf中,但是建议写在/etc/httpd/conf.d/目录,为每一个站点(域名)写一个配置文件xxx.conf

xxx.conf的格式如下

# file: /etc/http/conf.d/xxx.conf
# vhost: example.com
<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
</VirtualHost>

将上面的example.com改成你的域名即可。

另外,别忘了在/etc/httpd/conf/httpd.conf中开启“NameVirtualHost *:80”这一行,默认是关闭的,否则会出现如下错误:

[warn] _default_ VirtualHost overlap on port 80, the first has precedence

最后:service httpd restart

 

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注

3 + 20 =