云友“
bokie ”提到,不想让他人的域名访问到自己ECS服务器上的站点内容。
因为安装Apache后,在浏览器地址栏里输入ECS的公网地址,访问到的页面是默认站点的内容,如果这时有他人的域名解析到这个公网IP地址,也会访问到相同的内容。
本例环境:Debian 8,通过apt-get安装了apache web,yun.anqun.org 和 portal.anqun.org 两个域名均解析到了ECS的公网IP地址:121.43.110.72
过程:
1. 打开apache的虚拟主机配置文件目录,/etc/apache2/sites-enabled ,里边有一个默认站点的配置文件,000-default.conf,内容如下:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
其中没有设置ServerName,且提示这个站点将作为默认站点,即如果当请求域名不存在时,将显示该站点的内容。
2. 现在在 /etc/apache2/sites-enabled 目录里,新创建一个虚拟站点 yun.anqun.org 的配置文件 111-yun_anqun_org.conf ,简化后的内容如下:
<VirtualHost *:80>
ServerName yun.anqun.org
DocumentRoot /var/www/html/yun.anqun.org
</VirtualHost>
3. 保存后重启apache2服务,在浏览器里分别访问
http://yun.anqun.org/ ,
http://portal.anqun.org/,
http://121.43.110.72/ ,结果显示,后两个网址访问到的都是默认站点的内容
[attachment=120124]
[attachment=120125]
[attachment=120126]
所以,如果想不让他人的域名访问到自己的站点内容,可将默认站点设置为其它内容(或空白)即可。
-------------------------
的帖子很精彩!希望很快能再分享您的下一帖!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。