1、Apache2.4.1曾经:

第一种 直接拒绝訪问

打开 httpd.conf  文件,将一下配置追加到文件最后。
#直接拒绝全部非法域名
<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>



#同意的域名
<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  文件,将一下配置追加到文件最后。
#全部非法域名跳转到指定文件夹或文件
<VirtualHost *:80>
#指定文件夹或文件
DocumentRoot "/yun/www"
ServerName *
ServerAlias *
</VirtualHost>
#同意的域名
<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

第三种:配置单个域名拒绝或跳转(不建议使用)

# 拒绝单个域名 (若要拒绝多个 须要配置多个VirtualHost)
<VirtualHost *:80>
ServerName www.拒绝的域名
ServerAlias www.拒绝的域名
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>

2、Apache2.4.1 以后:

apache2.4.1 以后不再须要NameVirtualHost以及不再支持ServerName * 这样的写法。

使用ServerName * 会报Invalid ServerName “*” use ServerAlias to set multiple server names.

第一种:直接拒绝

打开 httpd.conf  在文件末尾加上一下代码:

#禁止全部非法域名
<VirtualHost *:80>
ServerName serverip
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>


#同意訪问的域名
<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  在文件末尾加上一下代码:

#禁止全部非法域名
<VirtualHost *:80>
DocumentRoot "/alidata/www"
ServerName serverip
ServerAlias *
<Location /alidata/www>
Order Allow,Deny
Allow from all
</Location>
</VirtualHost>
#同意訪问的域名
<VirtualHost *:80>
DocumentRoot /alidata/www
ServerName www.你的域名
ServerAlias www.<span style="font-family: Arial, Helvetica, sans-serif;">你的域名</span>
<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

第三种:配置单个域名拒绝或跳转(不建议使用)

# 拒绝单个域名 (若要拒绝多个 须要配置多个VirtualHost)
<VirtualHost *:80>
ServerName www.game673.com
ServerAlias www.game673.com
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>

配置server禁止全部非法域名 訪问自己的server的更多相关文章

  1. 配置 Apache 服务器禁止所有非法域名 访问自己的服务器

    .http2..1以前: 第一种 直接拒绝访问 打开 httpd.conf 文件,将一下配置追加到文件最后. <pre name="code" class="htm ...

  2. 配置Nginx防止直接用IP訪问Webserver

    看了非常多Nginx的配置,好像都忽略了ip直接訪问Web的问题.这样理论上不利于SEO优化,所以我们希望能够避免直接用IP訪问站点.而是域名訪问.详细怎么做呢.看以下. 官方文档中提供的方法: If ...

  3. 您可能试图从server上的安全浏览器訪问此站点。请启用脚本然后又一次载入此页。

    您可能试图从server上的安全浏览器訪问此站点.请启用脚本然后又一次载入此页.         我使用域Admin组的账户登入SharePoint2010的server,打开SharePoint首页 ...

  4. CentOS 配置httpd使局域网能够正常訪问

    [转载请注明出处: 钱国正的专栏http://blog.csdn.net/qianguozheng/article/details/37611859] 问题: 在CentOS上安装apache,配置好 ...

  5. SQL Server未找到或无法訪问server问题解决

    问题信息:"在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法訪问服务器.请验证实例名称是否正确而且 SQL Server 已配置为同意远程连接. (pr ...

  6. IIS中遇到无法预览的问题(HTTP 错误 401.3 - Unauthorized 因为 Web server上此资源的訪问控制列表(ACL)配置或加密设置,您无权查看此文件夹或页面。)

    在IIS中  依次运行例如以下操作: 站点--编辑权限--共享(为了方便能够直接将分享对象设置为everyone)--安全(直接勾选 everyone )--应用--确定.

  7. apache禁止訪问某些文件或文件夹的方法

    [apache配置禁止訪问] 1. 禁止訪问某些文件/文件夹 添加Files选项来控制,比方要不同意訪问 .inc 扩展名的文件,保护php类库: <Files ~ "\.inc$&q ...

  8. JBoss AS 7之域名直接訪问配置(The Return Of The King)

    1.6域名直接訪问配置 部署JBoss的时候,默认情况下訪问是须要加项目名字才可以訪问的. 可是怎样才可以"IP+port"訪问呢?以下将解说怎样配置. 配置域名訪问须要在项目以下 ...

  9. NGINX之——配置HTTPS加密反向代理訪问–自签CA

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46695495 出于公司内部訪问考虑,採用的CA是本机Openssl自签名生成的,因 ...

随机推荐

  1. [CF] 948A Protect Sheep

    A. Protect Sheep time limit per test1 second memory limit per test256 megabytes inputstandard input ...

  2. python基础知识06-函数基础和函数参数

    函数基础和函数参数 可迭代对象:序列类型 range . 1.函数的定义 def 函数名(参数): pass return 表达式 ,不能是赋值语句.不写默认返回None.用逗号隔开返回一个元组. 函 ...

  3. style对象的cssText方法

    cssText 本质是什么? cssText 的本质就是设置 HTML 元素的 style 属性值. cssText 怎么用? domElement.style.cssText = "col ...

  4. 调用hcm接口同步员工数据更新员工信息没有同步到bdm

    原来是更新的时候,baseEmployeeEntity的id为空,这时候需要把原先的baseEmployeeEntity1的id赋值给baseEmployeeEntity,问题解决

  5. 【转载】CentOS6.5升级手动安装GCC4.8.2

    一.简易安装 操作环境 CentOS6.5 64bit,原版本4.4.7,不能支持C++11的特性~,希望升级到4.8.2 不能通过yum的方法升级,需要自己手动下载安装包并编译 1.1 获取安装包并 ...

  6. python006 Python3 运算符

    Python3 运算符什么是运算符?本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符.Python语言 ...

  7. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  8. codeforces 1041 d 二分

    题意转化:有一些区间,要求选一些连续的区间.两两区间间隔的和要求小于H.要求区间的长度和尽可能长. 二分区间长度的和,check一下就行 #include <bits/stdc++.h> ...

  9. python学习之-- redis模块基本介绍

    数据缓存系统: 1:mongodb:是直接持久化,直接存储于硬盘的缓存系统 2:redis: 半持久化,存储于内存和硬盘 3:memcache:数据只能存储在内存里的缓存系统关于memcache 学习 ...

  10. CodeForces 598C Nearest vectors

    这题对精度要求很高.用atan2吧... #include<iostream> #include<cstring> #include<cmath> #include ...