Configure Apache server to prohibit all illegal domain names from accessing your server

Source: Internet
Author: User
1. Before http2.4.1: the first method is to directly access the httpd. conf file and append the configuration to the end of the file.
# Directly deny all illegal domain names <virtualhost *: 80> servername * serveralias * <location/> order allow, denydeny from all </location> errorlog "/alidata/log/httpd/error. log "customlog"/alidata/log/httpd/info. log "common </virtualhost>
 
 
 
# Allowed domain names <virtualhost *: 80> DocumentRoot/alidata/wwwservername www. your domain name serveralias www. your domain name <directory "/alidata/www"> options indexes followsymlinks AllowOverride all order allow, deny allow from all </directory> <ifmodule mod_rewrite.c> rewriteengine onrewriterule ^ (. *)-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>

Restart apache service: Service httpd restart 2. Jump to the specified directory or file to open the httpd. conf file and append the configuration to the end of the file. 
# Redirect all illegal domain names to a specified directory or file <virtualhost *: 80> # specify a directory or file DocumentRoot "/Yun/www" servername * serveralias * </virtualhost>
# Allowed domain names <virtualhost *: 80> DocumentRoot/alidata/wwwservername www. your domain name serveralias www. your domain name <directory "/alidata/www"> options indexes followsymlinks AllowOverride all order allow, deny allow from all </directory> <ifmodule mod_rewrite.c> rewriteengine onrewriterule ^ (. *)-HTM -(. *) $. PHP? Rewriterule ^ (. *)/simple/([a-z0-9 \ _] + \. html) $/simple/index. php? </Ifmodule> # Error Log errorlog "/alidata/log/httpd/error. log" customlog "/alidata/log/httpd/info. log" common </virtualhost>
Restart apache service: Service httpd restart
Third: configure a single domain name to reject or redirect (not recommended)
# Reject a single domain name (if you want to reject multiple domain names, you need to configure multiple virtualhosts) <virtualhost *: 80> servername www. the domain name serveralias www. rejected domain names <location/> order allow, denydeny from all </location> </virtualhost>


2. After http2.4.1:

Http2.4.1 and later do not require namevirtualhost or servername. When servername * is used, invalid servername "*" use serveralias to set multiple server names will be reported.

First: Direct rejection

Open httpd. conf and add the code at the end of the file:

# Disable all illegal domain names <virtualhost *: 80> servername server ipserveralias * <location/> order allow, denydeny from all </location> </virtualhost>

 
 
# The domain name <virtualhost *: 80> DocumentRoot/alidata/wwwservername www. your domain name serveralias www. your domain name <directory "/alidata/www"> options indexes followsymlinks AllowOverride all order allow, deny allow from all </directory> <ifmodule mod_rewrite.c> rewriteengine onrewriterule ^ (. *)-HTM -(. *) $. PHP? Rewriterule ^ (. *)/simple/([a-z0-9 \ _] + \. html) $/simple/index. php? </Ifmodule> # error log storage location: errorlog "/alidata/log/httpd/error. log" customlog "/alidata/log/httpd/info. log" common </virtualhost>

Restart apache service: Service httpd restart 

Type 2: jump to a specified directory or file

Open httpd. conf and add the code at the end of the file:

# Disable all illegal domain names <virtualhost *: 80> DocumentRoot "/alidata/www" servername server ipserveralias * <location/alidata/WWW> order allow, denyallow from all </location> </virtualhost>
<span style="font-family: Arial, Helvetica, sans-serif;"></span>
# The domain name <virtualhost *: 80> DocumentRoot/alidata/wwwservername www. your domain name serveralias www. <span style = "font-family: Arial, Helvetica, sans-serif; "> your domain name </span> <directory"/alidata/www/FDT "> options indexes followsymlinks AllowOverride all order allow, deny allow from all </directory> <ifmodule mod_rewrite.c> rewriteengine onrewriterule ^ (. *)-HTM -(. *) $. PHP? Rewriterule ^ (. *)/simple/([a-z0-9 \ _] + \. html) $/simple/index. php? </Ifmodule> # error log storage location: errorlog "/alidata/log/httpd/error. log" customlog "/alidata/log/httpd/info. log" common </virtualhost>

Restart apache service: Service httpd restart

Third: configure a single domain name to reject or redirect (not recommended)
# Reject a single domain name (if you want to reject multiple domain names, you need to configure multiple virtualhosts) <virtualhost *: 80> servername www. game673.comserveralias www.game673.com <location/> order allow, denydeny from all </location> </virtualhost>




Configure Apache server to prohibit all illegal domain names from accessing your server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.