、http2..1以前:
第一种 直接拒绝访问
打开 httpd.conf 文件,将一下配置追加到文件最后。
<pre name="code" class="html"><pre name="code" class="html"><pre name="code" class="html">#直接拒绝所有非法域名
<VirtualHost *:>
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 *:>
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-\_]+\.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 *:>
#指定目录或文件
DocumentRoot "/yun/www"
ServerName *
ServerAlias *
</VirtualHost> </pre><pre name="code" class="html"><pre name="code" class="html">#允许的域名
<VirtualHost *:>
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-\_]+\.html)$ /simple/index.php?
</IfModule>
#错误日志
ErrorLog "/alidata/log/httpd/error.log"
CustomLog "/alidata/log/httpd/info.log" common
</VirtualHost> 重启apache服务:service httpd restart 、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 *:>
ServerName 服务器ip
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost> <pre name="code" class="html">#允许访问的域名
<VirtualHost *:>
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-\_]+\.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 *:>
DocumentRoot "/alidata/www"
ServerName 服务器ip
ServerAlias *
<Location /alidata/www>
Order Allow,Deny
Allow from all
</Location>
</VirtualHost> </pre> <pre name="code" class="html">#允许访问的域名
<VirtualHost *:>
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-\_]+\.html)$ /simple/index.php?
</IfModule>
#错误日志保存位置
ErrorLog "/alidata/log/httpd/error.log"
CustomLog "/alidata/log/httpd/info.log" common
</VirtualHost> 重启apache服务:service httpd restart

配置 Apache 服务器禁止所有非法域名 访问自己的服务器的更多相关文章

  1. wamp配置apache虚拟主机支持多域名访问localhost

    1.背景: 在进行网站开发的时候,通常需要以http://localhost或者127.0.0.1等地址来访问本地环境的网站.不过随着开发项目的增多,需要每次先访问localhost然后再选项目,显得 ...

  2. apache2.4 只允许合法域名访问网站 禁止使用ip、非法域名访问

    1.ip访问禁用ip访问 只能对应端口有效<VirtualHost *:80> ServerName xx.xx.xx.xx ServerAlias * <Location /> ...

  3. 配置server禁止全部非法域名 訪问自己的server

    1.Apache2.4.1曾经: 第一种 直接拒绝訪问 打开 httpd.conf  文件,将一下配置追加到文件最后. #直接拒绝全部非法域名 <VirtualHost *:80> Ser ...

  4. 通过域名访问部署在服务器上的javaweb项目

    因为对域名访问什么也不了解,遇到问题就有种不知道从哪里下手的茫然,也就更不知道错在哪里,前前后后一共折腾了一天多,最后问了阿里客服才成功弄出来,因此记录一下. 关于服务器的购买.配置,及域名的备案解析 ...

  5. nginx 禁止未绑定的域名访问

    nginx 禁止未绑定的域名访问 方法1: server { listen 80 default_server; #不指定 server_name, server_name 默认为"&quo ...

  6. Nginx配置实例-负载均衡实例:平均访问多台服务器

    场景 Nginx配置实例-反向代理实例:根据访问的路径跳转到不同端口的服务中: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  7. Apache下禁止使用IP直接访问本站的配置方法

    现在管的严啊,上面要求不能使用IP直接访问服务器,把apache配置做下调整就行了.方法如下: 打开apache的配置文件 # vi /usr/local/apache2/conf/extra/htt ...

  8. nginx 禁止非指定域名访问

    nginx 配置如下: server { listen 80 default_server; server_name _; return 404; } # server conf server { l ...

  9. docker配置cdn-容器内可以通过域名访问

    添加docker的cdn配置 # 没有这个文件创建 vim /etc/docker/daemon.json 添加内容如下 { "dns":["8.8.8.8", ...

随机推荐

  1. Dijkstra算法简单实现(C++)

    图的最短路径问题主要包括三种算法: (1)Dijkstra (没有负权边的单源最短路径) (2)Floyed (多源最短路径) (3)Bellman (含有负权边的单源最短路径) 本文主要讲使用C++ ...

  2. mysql踩坑

    com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '****** ...

  3. Django框架基础知识14-类视图

    MTV view视图 wsgi函数 def index(request): .... return HttpResponse() 特定的HTTP方法.get,post可以定义单独的方法 继承,多继承, ...

  4. 杭电 1856 More is better (并查集求最大集合)

    Description Mr Wang wants some boys to help him with a project. Because the project is rather comple ...

  5. 【02】一个实现h5的拖放的整个过程-魔芋

    [02]拖放的整个过程-魔芋   01,创建2个元素,一个为拖放元素dragEle,一个是存放的元素targetEle.添加一些样式.   <div class="dragEle&qu ...

  6. luogu3959 宝藏

    状压搜索轻轻松松就过了--考场上代码太丑了T了几个点 #include <iostream> #include <cstring> #include <cstdio> ...

  7. Centos6.5安装Oracle11.2.0.4 RAC(完整版)

    环境参数:Linux:Centos6.5 Grid和Oracle:11.2.0.4 一.环境配置 1.配置Node1和Node2两个节点之间的网卡 Node1: [root@rac1 network- ...

  8. Java并发编程:自己动手写一把可重入锁

    关于线程安全的例子,我前面的文章Java并发编程:线程安全和ThreadLocal里面提到了,简而言之就是多个线程在同时访问或修改公共资源的时候,由于不同线程抢占公共资源而导致的结果不确定性,就是在并 ...

  9. 后缀排序(codevs 1500)

    题目描述 Description 天凯是MIT的新生.Prof. HandsomeG给了他一个长度为n的由小写字母构成的字符串,要求他把该字符串的n个后缀(suffix)从小到大排序. 何谓后缀?假设 ...

  10. 事件和委托: 第 6 页 .Net Framework中的委托与事件

    原文发布时间为:2008-11-01 -- 来源于本人的百度文章 [由搬家工具导入] .Net Framework中的委托与事件 尽管上面的范例很好地完成了我们想要完成的工作,但是我们不仅疑惑:为什么 ...