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