、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. ARP 协议

    1. 什么是ARP协议? 网络层以上的协议用IP地址来标识网络接口,但以太数据帧传输时,以物理地址来标识网络接口.因此我们需要进行IP地址与物理地址之间的转化.对于IPv4来说,我们使用ARP地址解析 ...

  2. 每日命令:(14)tune2fs

    tune2fs简介 tune2fs是调整和查看ext2/ext3文件系统的文件系统参数,Windows下面如果出现意外断电死机情况,下次开机一般都会出现系统自检.Linux系统下面也有文件系统自检,而 ...

  3. 条款31:将文件间的编译依存关系降至最低(Minimize compilation dependencies between files)

    NOTE1: 1.支持“编译依存性最小化”的一般构想是:相依于声明式,不要相依于定义式.基于此构想的两个手段是Handle classes 和 Interface classes. 2.程序库头文件应 ...

  4. Cannot delete or update a parent row: a foreign key constraint fails....

    在操作”小弟“这张表时候报错 想在“小弟”上面加入数据或者更新数据,就要听老大的, 这句话后面跟着的表就是“老大”,必须老大有数据索引,“小弟“才可以加入或者更新 查看“小弟”表的外键,会发现有对“老 ...

  5. Android开发——短信电话拦截/接听电话

    1.短信拦截 首先需要声明的是,Android4.4版本以上,如果想做到短信拦截,必须成为default sms,把所有短信相关的功能都包揽了,然后再做短信拦截.但这种做法,适配性和兼容性的工作是非常 ...

  6. String字符串去掉双引号

    public static String stringReplace(String str) { //去掉" "号 String str= str.replace("\& ...

  7. spring的IOC和DI

    https://blog.csdn.net/fuzhongmin05/article/details/55802816 (1)IOC:控制反转,把对象创建交给spring进行配置 (2)DI:依赖注入 ...

  8. spring的IOC底层原理

    我们调用一个类的方法,首先是User user=new  User(),对象调用这个方法,user.add(),这种方法有一个缺陷就是代码的耦合度太高,比如你的servlet调用User类里的方法,需 ...

  9. maven+Hibernate+mysql环境搭建

    项目结构图如下 一,首先是添加依赖pom.xml <?xml version="1.0" encoding="UTF-8"?> <projec ...

  10. hihoCoder#1141 二分·归并排序之逆序对

    原题地址 又是一道WA成狗的题,最后发现原来是结果溢出了.. 代码: #include <iostream> #include <cstring> using namespac ...