您的位置:首页 > 运维架构 > Linux

阿里云 centos 配置多个域名

2017-12-16 17:54 197 查看
阿里云 服务器 httpd.conf 配置文件中,配置多个域名是需要开启

NameVirtualHost *:80


原因:

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

ECS 实例上的网站被人恶意指向,例如,您的实例 IP 地址为 123.123.123.123,正常服务的域名为 www.abc.com ,

恶意用户使用其他的域名 www.fake.com , 指向 123.123.123.123,此时客户端访问 www.fake.com

时会出现您的网站内容。

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

Apache 版本号 ECS 实例上的网站

2.2.15 http://t1.huigher.cn/

http://p1.huigher.cn/

打开 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>


注意:当客户端携带的 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>


注意:这一步告知 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>


执行命令 /etc/httpd/bin/apachectl restart 重启 Apache 服务。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache centos 域名