配置 Apache 服務器禁止所有非法域名 訪問自己的服務器
1、http2.4.1以前:
第一種 直接拒絕訪問
打開 httpd.conf 文件,將一下配置追加到文件最后。
<pre name="code" class="html"><pre name="code" class="html"><pre name="code" class="html">#直接拒絕所有非法域名
<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>
</pre><pre name="code" class="html"><pre name="code" class="html">#允許的域名
<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
第二種 跳轉(zhuǎn)到指定目錄或文件
打開 httpd.conf 文件,將一下配置追加到文件最后。
#所有非法域名跳轉(zhuǎn)到指定目錄或文件
<pre name="code" class="html"><pre name="code" class="html"><VirtualHost *:80>
#指定目錄或文件
DocumentRoot "/yun/www"
ServerName *
ServerAlias *
</VirtualHost>
</pre><pre name="code" class="html"><pre name="code" class="html">#允許的域名
<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
2、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 *:80>
ServerName 服務器ip
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
<pre name="code" class="html">#允許訪問的域名
<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
第二種:跳轉(zhuǎn)到指定目錄或文件
打開 httpd.conf 在文件末尾加上一下代碼:
<pre name="code" class="html"><pre name="code" class="html">#禁止所有非法域名
<VirtualHost *:80>
DocumentRoot "/alidata/www"
ServerName 服務器ip
ServerAlias *
<Location /alidata/www>
Order Allow,Deny
Allow from all
</Location>
</VirtualHost>
</pre>
<pre name="code" class="html">#允許訪問的域名
<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
以上所述是小編給大家介紹的配置 Apache 服務器禁止所有非法域名 訪問自己的服務器,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
windows apache環(huán)境下部署SSL證書讓網(wǎng)站支持https的配置方法
由于網(wǎng)站劫持與chrome瀏覽器默認不用https的提示網(wǎng)站不安全的原因,今天把SSL證書部署分享一下,希望能幫到大家2020-09-09
Lamp環(huán)境下設置綁定apache域名的方法分析
這篇文章主要介紹了Lamp環(huán)境下設置綁定apache域名的方法,簡單分析了Lamp環(huán)境下的Apache域名綁定設置相關屬性、功能與操作技巧,需要的朋友可以參考下2018-03-03
Linux+php+apache+oracle環(huán)境搭建之CentOS下源碼編譯安裝PHP
環(huán)境搭建過程中,編譯安裝PHP最艱辛。需要安裝的依賴組件太多。現(xiàn)在整理記錄一下。也希望對讀者能有所幫助2014-08-08
shell腳本報錯:"[: =: unary operator expected"解決辦法
這篇文章主要介紹了shell腳本報錯:"[: =: unary operator expected"解決辦法的相關資料,需要的朋友可以參考下2017-03-03
Linux中查看指定文件夾內(nèi)各個子文件夾內(nèi)的文件數(shù)量
今天小編就為大家分享一篇關于Linux中查看指定文件夾內(nèi)各個子文件夾內(nèi)的文件數(shù)量,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01
linux下用戶程序同內(nèi)核通信詳解(netlink機制)
這篇文章主要介紹了linux下用戶程序同內(nèi)核通信詳解(netlink機制),涉及netlink,內(nèi)核模塊,用戶程序的介紹等相關內(nèi)容,小編覺得還是挺不錯的,這里分享給大家,需要的朋友可以參考下2018-01-01

