铿鸟百科网

当前位置:主页 > 百科 > 电脑百科 >

Apache服务器禁止非法域名和使用ip访问服务器的设置

Apache服务器禁止非法域名和使用ip访问服务器的设置

时间:2025-07-07 来源:铿鸟百科网 收集整理:小编 阅读:
导读:别人将域名非法解析到自己的服务器上,站长会经常碰到,Apache服务器需要做如下设置才能禁止这种情况,该操作也能禁止使用服务器的ip访问。http2.4.1 以后:http2.4.1 以后不再需要NameVirtualHost以及不再支持S

别人将域名非法解析到自己的服务器上,站长会经常碰到,Apache服务器需要做如下设置才能禁止这种情况,该操作也能禁止使用服务器的ip访问。

http2.4.1 以后:

http2.4.1 以后不再需要NameVirtualHost以及不再支持ServerName * 这种写法。

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

第一种:直接拒绝

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

#禁止所有非法域名

<VirtualHost *:80>

ServerName 服务器ip

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 服务器ip

ServerAlias *

<Location /alidata/www>

Order Allow,Deny

Allow from all

</Location>

</VirtualHost>

#允许访问的域名

<VirtualHost *:80>

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-9\_]+\.html)$ /simple/index.php?

</IfModule>

#错误日志保存位置

ErrorLog "/alidata/log/httpd/error.log"

CustomLog "/alidata/log/httpd/info.log" common

</VirtualHost>

重启apache服务生效

http2.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 文件,将一下配置追加到文件最后。

#所有非法域名跳转到指定目录或文件

<pre name="code" class="html"><pre name="code" class="html"><VirtualHost *:80>

#指定目录或文件

DocumentRoot "/yun/www"

ServerName *

ServerAlias *

</VirtualHost>

#允许的域名

<VirtualHost *:80>

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-9\_]+\.html)$ /simple/index.php?

</IfModule>

#错误日志

ErrorLog "/alidata/log/httpd/error.log"

CustomLog "/alidata/log/httpd/info.log" common

</VirtualHost>

重启apache服务:service httpd restart

相关阅读

  • win10怎么快速关闭屏幕?win10快速关闭屏幕方法

    win10怎么快速关闭屏幕?win10快速关闭屏幕方法

    估计很多用 Win10 的人都会想要快速锁屏来保护个人隐私,但是也有人不知道怎么快速关掉屏幕。其实很简单,你可以直接按 Win + L 快捷键,或者右键点击桌面上的空白地方,然后选择快捷方式就可以啦。下面我们就来详细说一下 Win10 快速

  • 苹果iOS 17.4 Beta版开放侧载功能,但iPad不在列

    苹果iOS 17.4 Beta版开放侧载功能,但iPad不在列

    1月27日消息,苹果公司近日针对欧盟《数字市场法》作出了响应,上线了iOS 17.4 Beta版,向欧盟用户开放了侧载功能。然而,尽管iPadOS与iOS在本质上并无太大差异,但iPad并不支持侧载功能。这意味着,安装第三方应用商店以及从第

  • 极氪20万台新能源汽车里程碑达成

    极氪20万台新能源汽车里程碑达成

    1月8日消息,国内新能源汽车市场再传捷报。极氪汽车今日欣喜公布,经过26个月的不懈努力,其累计交付汽车数量已突破20万台大关。这一成就不仅彰显了极氪在新能源领域的强劲实力,更使其持续刷新着新势力品牌的最快交付纪录,同时保持着全球唯一的新能源

  • Win11系统intel核显控制面板怎么打开-打开intel核显控制面板的方法

    Win11系统intel核显控制面板怎么打开-打开intel核显控制面板的方法

    你晓得吗?有些小伙伴想开自己电脑的intel核显控制面板来看显卡驱动信息。里面可以检查更新驱动。但是,他们不知道怎么开这个面板。如果也想试试看的话,可以看看下面的操作方法哦!打开intel核显控制面板的方法1. 右键桌面空白处,就能打开英特

  • Windows10玩GTA5闪退怎么解决?Windows10玩GTA5闪退解决方法

    Windows10玩GTA5闪退怎么解决?Windows10玩GTA5闪退解决方法

    Windows10玩GTA5闪退怎么解决?GTA5是一款非常知名的游戏,很多的玩家都在畅玩,但是很多的用户们在玩耍这一款游戏的时候,遇到了自己电脑玩GTA5会闪退,这个问题我们怎么解决呢?下面小编为大家带来详细的解决方法介绍,快来看看吧!

  • 极氪第二款MPV车型“CM2E”谍照曝光,或于2024年上半年亮相

    极氪第二款MPV车型“CM2E”谍照曝光,或于2024年上半年亮相

    1月17日消息,近日,知名汽车博主@SugarDesign在社交媒体上发布了极氪品牌旗下第二款MPV车型——内部代号“CM2E”的谍照。据推测,新车可能为小型MPV,有望于2024年上半年与大家正式见面。  从曝光的谍照中可以看出,极氪CM