阿里云 centos 配置多个域名
2017-12-16 17:54
197 查看
阿里云 服务器 httpd.conf 配置文件中,配置多个域名是需要开启
原因:
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 配置文件,加入以下内容:
加入代码
加入以下代码。
注意:当客户端携带的 host 名不在之后设置的网站域名内时,会指向一个 403 错误页面告知用户域名非法,其中 DocumentRoot 是放置错误提示页面的目录,在下面可以放置一个简单的 html 页面提示用户正在访问非法域名。
加入以下代码。
注意:这一步告知 Apache 合法的网站主机头,您需要根据实际情况修改这个代码块内容,如示例中的 p1.huigher.cn 和 t1.huigher.cn。
执行命令 /etc/httpd/bin/apachectl restart 重启 Apache 服务。
若您希望其他域名访问您的网站时直接返回 403 错误:
修改第二步中的代码为以下形式:
执行命令 /etc/httpd/bin/apachectl restart 重启 Apache 服务。
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 服务。
相关文章推荐
- 阿里云服务器Linux CentOS安装配置(七)域名解析
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
- 阿里云服务器配置开发环境第二章:Centos7.3安装jdk1.8以及环境配置
- CentOS 7运维管理笔记(8)----Apache基于域名的虚拟主机配置
- 阿里云centos 安装和配置 DokuWiki
- CentOS 下apache基于域名的多虚拟主机配置问题-新问题
- 阿里云服务器Linux CentOS安装配置(11)安装Wordpress
- 阿里云服务器(windows)配置项目域名
- Centos Bind 配置 域名 MX记录
- 阿里云Centos配置iptables防火墙
- 在centos阿里云服务器上配置apache+php+mysql环境
- 如何在阿里云Centos7.0上配置java web环境
- 阿里云服务器CentOS 5.7(64位)安装配置LAMP服务器(Apache+PHP5+MySQL)
- 阿里云项目部署 并且配置域名
- 阿里云tomcat配置虚拟路径和域名访问
- 阿里云CentOS 7下配置nginx环境
- 阿里云Centos配置LNMP环境
- 阿里云服务器配置开发环境第三章:Centos7.3安装Tomcat8以及环境配置
- 【CentOS】阿里云ECS申请CA证书配置SSL
- Centos6.5生成环境配置--nginx1.9 + PHP+可多个tomcat(多个端口)+多域名+java web 负载均衡