回忆源回忆源回忆源

阿里云 centos 配置多个域名

阿里云 服务器 httpd.conf 配置文件中,配置多个域名是需要开启

 NameVirtualHost *:80

原因:

Apache 禁止未经许可的域名访问 ECS 上的网站

ECS 实例上的网站被人恶意指向,例如,您的实例 IP 地址为 156.156.156.156,正常服务的域名为 www.wtc.com ,
恶意用户使用其他的域名 www.hare.com , 指向 156.156.156.156,此时客户端访问 www.hare.com
时会出现您的网站内容。

通过 Apache 的虚拟主机可以变通的解决这个问题。以如下场景为例:

Apache 版本号 ECS 实例上的网站
例如: http://a1.wtzyw.com/
           http://b1.wtzyw.com/
打开 Apache 的实际配置文件,如执行命令 vi /etc/httpd/conf/httpd.conf 打开 CentOS 的 Apache 配置文件,加入以下内容:

加入代码 NameVirtualHost *:80,告知 Apache 使用基于 host 名的虚拟主机功能:

加入以下代码。

 <ViretualHost *:80>
         DocumentRoot /var/www/html/error/
         ServerName *
         ErrorLog logs/dummy-host.example.com-error_log
         CustomeLog logs/dummy-host.example.com-access_log common  
 </ViretualHost>123456

注意:当客户端携带的 host 名不在之后设置的网站域名内时,会指向一个 403 错误页面告知用户域名非法,其中 DocumentRoot 是放置错误提示页面的目录,在下面可以放置一个简单的 html 页面提示用户正在访问非法域名。
加入以下代码。

<VirtualHost *:80>
     ServerAdmin p1@huigher.cn
     DocumentRoot /var/www/html/another/
     ServerName p1.huigher.cn
     ErrorLog logs/p1.huigher.cn-error_loh
     CustomLog logs/p1.huigher.cn-access_log common
</VirtualHost>
<VirtualHost *:80>
     ServerAdmin t1@huigher.cn
     DocumentRoot /var/www/html/
     ServerName t1.huigher.cn
     ErrorLog logs/t1.huigher.cn-error_loh
     CustomLog logs/t1.huigher.cn-access_log common
</VirtualHost>1234567891011121314

注意:这一步告知 Apache 合法的网站主机头,您需要根据实际情况修改这个代码块内容,如示例中的 p1.huigher.cn 和 t1.huigher.cn。
执行命令 /etc/httpd/bin/apachectl restart 重启 Apache 服务。

若您希望其他域名访问您的网站时直接返回 403 错误:

修改第二步中的代码为以下形式:

 <VirtualHost *:80>
         DucumentRoot /var/www/html/error/         ServerName * <Location>
         Order Allow, Deny         Deny from all
 </Location>
         ErrorLog logs/dummy-host.example.com-error_log         CustomLog logs/dummy-host.example.com-access_log commom </VirtualHost>12345678910

执行命令 /etc/httpd/bin/apachectl restart 重启 Apache 服务。



未经允许不得转载:回忆源 » 阿里云 centos 配置多个域名