Chinaunix首页 | 论坛 | 博客
  • 博客访问: 220632
  • 博文数量: 70
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-09 09:16
个人简介

淡泊以明志,宁静以致远。

文章分类

全部博文(70)

分类: LINUX

2017-09-15 01:52:07

Apache如何禁止非法域名 访问自己的服务器呢?在网上搜索了很多篇文章,由于大部分雷同且存在不全面的现象,导致无法有效设置。经过一番苦苦搜寻,终于在经典篇幅和apache虚拟主机配置文字综合后,在 httpd.conf 中增加网上很多容易忘记的 NameVirtualHost *:80 ,从而使得可以设置生效。

Apache2.4.1以前

打开 httpd.conf  文件,将以下配置追加到文件最后。

####################################################

点击(此处)折叠或打开

  1. #允许的域名 
  2. NameVirtualHost *:80 #非常重要的虚拟主机设置,如果忽略此处,则特定主机设置无法生效。
  3. <VirtualHost *:80>
  4.     DocumentRoot D:\website\htdocs
  5.     ServerName www.你的域名
  6.     ServerAlias www.你的域名
  7.     <Directory "D:\website\htdocs">
  8.         Options Indexes FollowSymLinks
  9.         AllowOverride all
  10.         Order allow,deny
  11.         Allow from all
  12.     </Directory>
  13.     <IfModule mod_rewrite.c>
  14.         RewriteEngine On
  15.         RewriteRule ^(.*)-htm-(.*)$ .php?
  16.         RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php?
  17.     </IfModule>
  18.     ErrorLog "logs/error.log"
  19.     CustomLog "logs/error.log" common
  20. </VirtualHost>

  21. #直接拒绝所有非法域名
  22. <VirtualHost *:80>
  23.   ServerName *
  24.   ServerAlias *
  25.   <Location />
  26.     Order Allow,Deny
  27.     Deny from all
  28.   </Location>
  29.   ErrorLog "logs/error.log"
  30.   CustomLog "logs/error.log" common
  31. </VirtualHost>

参考文章:
1. http://blog.csdn.net/chenxiruanhai/article/details/38876017
2. http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html
阅读(2015) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~