PHP World

首页 > System > Apache › 如何在CentOS给Apache2.4.20安装虚拟主机?

如何在CentOS给Apache2.4.20安装虚拟主机?

如何在CentOS给Apache2.4.20安装虚拟主机?要设置两个文件:
1. /usr/local/apache2/conf/httpd.conf
2. /usr/local/apache2/conf/extra/httpd-vhosts.conf

 这里计划加2个虚拟主机,2个域名分别是www.cheapglasses123.com , www.cheapglasses.net


设置httpd.conf

# vi /usr/local/apache2/conf/httpd.conf

找到:

#Virtual hosts
#Include etc//extra/httpd-vhosts.conf

改成:

#Virtual hosts
Include etc//extra/httpd-vhosts.conf

这样就启动apache的虚拟主机功能了。


再设置httpd-vhosts.conf, 打开它,加上如下代码:

<VirtualHost *:80>
    ServerAdmin admin@cheapglasses123.com
    DocumentRoot "/usr/local/apache2/htdocs/cheapglasses123.com"
    ServerName www.cheapglasses123.com
   # ServerAlias www.cheapglasses123.com
    ErrorLog "logs/cheapglasses123.com-error_log"
    CustomLog "logs/cheapglasses123.com-access_log" common
    <Directory "/usr/local/apache2/htdocs/cheapglasses123.com">
        Options Indexes
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@cheapglasses.net
    DocumentRoot "/usr/local/apache2/htdocs/cheapglasses.net"
    ServerName cheapglasses.net
    ServerAlias www.cheapglasses.net
    ErrorLog "logs/cheapglasses.net-error_log"
    CustomLog "logs/cheapglasses.net-access_log" common
    <Directory "/usr/local/apache2/htdocs/cheapglasses.net">
        Options Indexes
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Require all granted的意思是允许外网访问这个网站。如改成Require all denied .外网就访问不了这个站了。

这样两个配置文件就好了, 重新启动apache.

# /usr/local/apache2/bin/apachectl stop
# /usr/local/apache2/bin/apachectl start


上一篇:CentOS安装Apache错误

下一篇:返回列表

相关文章