配置 Apache 服务器禁止所有非法域名 访问自己的服务器
1、http2.4.1以前:
第一种 直接拒绝访问
打开 httpd.conf 文件,将一下配置追加到文件最后。
<pre name="code" class="html"><pre name="code" class="html"><pre name="code" class="html">#直接拒绝所有非法域名 <VirtualHost *:80> ServerName * ServerAlias * <Location /> Order Allow,Deny Deny from all </Location> ErrorLog "/alidata/log/httpd/error.log" CustomLog "/alidata/log/httpd/info.log" common </VirtualHost> </pre><pre name="code" class="html"><pre name="code" class="html">#允许的域名 <VirtualHost *:80> DocumentRoot /alidata/www ServerName www.你的域名 ServerAlias www.你的域名 <Directory "/alidata/www"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)-htm-(.*)$ .php? RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php? </IfModule> ErrorLog "/alidata/log/httpd/error.log" CustomLog "/alidata/log/httpd/info.log" common </VirtualHost>
重启apache服务:service httpd restart
第二种 跳转到指定目录或文件
打开 httpd.conf 文件,将一下配置追加到文件最后。
#所有非法域名跳转到指定目录或文件 <pre name="code" class="html"><pre name="code" class="html"><VirtualHost *:80> #指定目录或文件 DocumentRoot "/yun/www" ServerName * ServerAlias * </VirtualHost> </pre><pre name="code" class="html"><pre name="code" class="html">#允许的域名 <VirtualHost *:80> DocumentRoot /alidata/www/fdt ServerName www.fdt-art.com ServerAlias www.fdt-art.com <Directory "/alidata/www/fdt"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)-htm-(.*)$ .php? RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php? </IfModule> #错误日志 ErrorLog "/alidata/log/httpd/error.log" CustomLog "/alidata/log/httpd/info.log" common </VirtualHost>
重启apache服务:service httpd restart
2、http2.4.1 以后:
http2.4.1 以后不再需要NameVirtualHost以及不再支持ServerName * 这种写法。
使用ServerName * 会报Invalid ServerName “*” use ServerAlias to set multiple server names.
第一种:直接拒绝
打开 httpd.conf 在文件末尾加上一下代码:
<pre name="code" class="html"><pre name="code" class="html">#禁止所有非法域名 <VirtualHost *:80> ServerName 服务器ip ServerAlias * <Location /> Order Allow,Deny Deny from all </Location> </VirtualHost> <pre name="code" class="html">#允许访问的域名 <VirtualHost *:80> DocumentRoot /alidata/www ServerName www.你的域名 ServerAlias www.你的域名 <Directory "/alidata/www"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)-htm-(.*)$ .php? RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php? </IfModule> #错误日志保存位置 ErrorLog "/alidata/log/httpd/error.log" CustomLog "/alidata/log/httpd/info.log" common </VirtualHost>
重启apache服务:service httpd restart
第二种:跳转到指定目录或文件
打开 httpd.conf 在文件末尾加上一下代码:
<pre name="code" class="html"><pre name="code" class="html">#禁止所有非法域名 <VirtualHost *:80> DocumentRoot "/alidata/www" ServerName 服务器ip ServerAlias * <Location /alidata/www> Order Allow,Deny Allow from all </Location> </VirtualHost> </pre> <pre name="code" class="html">#允许访问的域名 <VirtualHost *:80> DocumentRoot /alidata/www/fdt ServerName www.fdt-art.com ServerAlias www.fdt-art.com <Directory "/alidata/www/fdt"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)-htm-(.*)$ .php? RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php? </IfModule> #错误日志保存位置 ErrorLog "/alidata/log/httpd/error.log" CustomLog "/alidata/log/httpd/info.log" common </VirtualHost>
重启apache服务:service httpd restart
原文链接:http://www.cnblogs.com/wujindong/p/7083362.html
(资源库 www.zyku.net)
上一篇:Apache 2.4.2无法访问错误代码为403的解决方法
栏 目:Apache
本文标题:配置 Apache 服务器禁止所有非法域名 访问自己的服务器
本文地址:https://www.zyku.net/apache/1442.html
您可能感兴趣的文章
- 05-04Vultr教程:在Ubuntu 17.04服务器上安装GUI环境Lubuntu-
- 03-28VtigerCRM 7安装服务器参数配置教程
- 02-29FastAdmin中代码和服务器安全建议分享
- 02-29Nginx服务器中设置禁止访问文件或目录的方法
- 11-02无法向会话状态服务器发出会话状态请求。请确保 ASP.N
- 11-02SQL Server 2012清除连接服务器历史记录的方法
- 04-23Linux下SVN服务器搭建的方法
- 04-18frp内网穿透工具多客户端,实现一台云服务器连接多个局
- 03-12Apache服务器利用.htaccess重写URL实现http自动跳转ht
- 10-22护卫神·主机大师,如何在自己的电脑上管理服务器网站
- 03-04wordpress为文章加上字数统计功能
- 02-16华为mate40网络加速功能设置教程
- 01-14小米手机地震预警如何开
- 02-12opporeno5修改app图标大小方法
- 04-01真我v11返回键设置方法
- 03-04wordpress网站全自动SEO优化的方法
- 01-19火力橙-火力橙应用软件功能介绍
- 09-11小米手机如何找回删除便签
- 02-23DedeCMS分类信息增加点击次数功能的方
- 02-20Zend studio for eclipse中使php可以
最近更新
阅读排行
猜你喜欢
- 11-05JS判断用户名及密码是否为空的方法
- 09-11goodnotes笔画粗细调整步骤分享
- 01-23荣耀x10充电指示灯怎么打开
- 04-21华为mate40pro设置防频闪教程
- 09-18华为mate40怎么设置通知栏图标顺序
- 01-14云上中文-云上中文应用软件功能介绍
- 09-22ios15怎么关闭专注模式
- 07-08华为钱包公交卡退卡退余额教程
- 12-07华为p50如何添加门禁卡
- 09-22微信专属月亮获取方法分享