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. 导出csv文件(php实现)

    <?php namespace App\Library\lib; class CsvLib { /** * [构造函数] * */ public function __construct() { ...

  2. python 装饰器(二): 加参数

    接上篇python 闭包&装饰器(一) 一.功能函数加参数:实现一个可以接收任意数据的加法器 源代码如下: def show_time(f): def inner(*x, **y): # 形参 ...

  3. SqlParameter[] parameters

    SqlParameter[] parameters = { new SqlParameter("@rdTypeName", readertype.rdTypeName), new ...

  4. javaweb 开发所需工具和入门教程文档等

    下载网址 1.JDK1.8下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.ht ...

  5. Codeforces Round #387 (Div. 2) A+B+C+D!

    A. Display Size 水题,暴力(数据都是水题).0:04 int main() { int n; while(~scanf("%d",&n)) { int mi ...

  6. [HNOI2009]梦幻布丁(链表+启发式合并)

    洛谷传送门 开始一个O(n^2)思路,每次每句要改变颜色的点,改变完颜色后重新计算颜色的段数,显然拉闸. 然后呢..然后就不会了. 看了别人博客,才知道有个叫做启发式合并的东西,就是把小的合并到大的上 ...

  7. BZOJ3027 - [CEOI2004]Sweet

    Portal Description 给出\(n(n\leq10),a,b(a,b\leq10^7)\)与\(\{c_n\}(c_i\leq10^6)\),求使得\(\sum_{i=1}^n x_i ...

  8. 我是一个线程 - IBM刘欣

    来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...

  9. http的N种请求

    GET通过请求URI得到资源 POST,用于添加新的内容 PUT用于修改某个内容 DELETE,删除某个内容 CONNECT,用于代理进行传输,如使用SSL OPTIONS询问可以执行哪些方法 PAT ...

  10. python之-- socket 基础篇

    socket 网络模块 注意事项:在python3中,所有数据的传输必须用bytes类型(bytes只支持ascii码)所以在发送数据的时候要么在发送的字符串前面加 'b',要么使用encode('u ...