配置 Apache 服务器禁止所有非法域名 访问自己的服务器
、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 服务器禁止所有非法域名 访问自己的服务器的更多相关文章
- wamp配置apache虚拟主机支持多域名访问localhost
1.背景: 在进行网站开发的时候,通常需要以http://localhost或者127.0.0.1等地址来访问本地环境的网站.不过随着开发项目的增多,需要每次先访问localhost然后再选项目,显得 ...
- apache2.4 只允许合法域名访问网站 禁止使用ip、非法域名访问
1.ip访问禁用ip访问 只能对应端口有效<VirtualHost *:80> ServerName xx.xx.xx.xx ServerAlias * <Location /> ...
- 配置server禁止全部非法域名 訪问自己的server
1.Apache2.4.1曾经: 第一种 直接拒绝訪问 打开 httpd.conf 文件,将一下配置追加到文件最后. #直接拒绝全部非法域名 <VirtualHost *:80> Ser ...
- 通过域名访问部署在服务器上的javaweb项目
因为对域名访问什么也不了解,遇到问题就有种不知道从哪里下手的茫然,也就更不知道错在哪里,前前后后一共折腾了一天多,最后问了阿里客服才成功弄出来,因此记录一下. 关于服务器的购买.配置,及域名的备案解析 ...
- nginx 禁止未绑定的域名访问
nginx 禁止未绑定的域名访问 方法1: server { listen 80 default_server; #不指定 server_name, server_name 默认为"&quo ...
- Nginx配置实例-负载均衡实例:平均访问多台服务器
场景 Nginx配置实例-反向代理实例:根据访问的路径跳转到不同端口的服务中: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...
- Apache下禁止使用IP直接访问本站的配置方法
现在管的严啊,上面要求不能使用IP直接访问服务器,把apache配置做下调整就行了.方法如下: 打开apache的配置文件 # vi /usr/local/apache2/conf/extra/htt ...
- nginx 禁止非指定域名访问
nginx 配置如下: server { listen 80 default_server; server_name _; return 404; } # server conf server { l ...
- docker配置cdn-容器内可以通过域名访问
添加docker的cdn配置 # 没有这个文件创建 vim /etc/docker/daemon.json 添加内容如下 { "dns":["8.8.8.8", ...
随机推荐
- CF528D Fuzzy Search 字符串匹配+FFT
题意: DNA序列,在母串s中匹配模式串t,对于s中每个位置i,只要s[i-k]到s[i+k]中有c就认为匹配了c.求有多少个位置匹配了t. 分析: 这个字符串匹配的方式,什么kmp,各种自动机都不灵 ...
- Windows 命令收集
定时关机命令:schtasks /create /tn "关机" /tr "shutdown /s" /sc once /st 23:55
- 9. InnoDB通用表空间
9. InnoDB通用表空间 通用表空间是InnoDB 使用CREATE TABLESPACE语法创建的共享表空间.本节中的以下主题描述了常规表空间功能和功能: 通用表空间功能 创建通用表空间 将表添 ...
- MongoDB中导入数据命令的使用(mongoimport)
MongoDB中导入数据命令的使用(mongoimport) 制作人:全心全意 语法: mongoimport <options> <file> 介绍: 该命令可以将CSV,T ...
- JS打包与代码分割
参考来源:https://github.com/ruanyf/webpack-demos#demo01-entry-file-source 后面的代码:https://github.com/94713 ...
- 【转】C# windows服务的创建与调试
Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...
- Android开发——使用ADB Shell命令实现模拟点击(支付宝自动转账实现)
首先声明,本人反对一切利用技术的违法行为 本文的实现代码已经销毁,本文以介绍流程为主 1.这里所说的模拟点击不是在自己的APP里点击,点自己APP上的控件没什么好说的 不仅是支付宝转账,其他的获取别人 ...
- Java学习之for循环打印菱形练习
for循环语句是Java程序设计中非常有用的循环语句.一个for循环可以用来重复执行某条语句,直到某个条件得到满足.在Java 5新增的加强的foreach语法,也非常有用. 1. for语句 for ...
- zoj 2001 Adding Reversed Numbers
Adding Reversed Numbers Time Limit: 2 Seconds Memory Limit: 65536 KB The Antique Comedians of M ...
- 【模板】manacher算法
传送门 某篇好文章 #include <cstdio> #include <cstring> #define N 22200000 #define min(x, y) ((x) ...