Configure the Apache server to block all illegal domain names from accessing your own server
- 2020-06-07 05:56:37
- OfStack
1. http2.4.1
The first outright denial of access
Open the httpd.conf file and append the configuration under 1 to the end of the file.
<pre name="code" class="html"><pre name="code" class="html"><pre name="code" class="html"># Reject all illegal domain names directly
<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"># Permitted domain names
<VirtualHost *:80>
DocumentRoot /alidata/www
ServerName 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 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>
Restart apache service: service httpd restart
Second, it jumps to a specified directory or file
Open the httpd. conf file and append the configuration under 1 to the end of the file.
# All illegal domain names redirect to the specified directory or file
<pre name="code" class="html"><pre name="code" class="html"><VirtualHost *:80>
# Specify a directory or file
DocumentRoot "/yun/www"
ServerName *
ServerAlias *
</VirtualHost>
</pre><pre name="code" class="html"><pre name="code" class="html"># Permitted domain names
<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>
# The error log
ErrorLog "/alidata/log/httpd/error.log"
CustomLog "/alidata/log/httpd/info.log" common
</VirtualHost>
Restart the apache service: service httpd restart
2. http2.4.1 After:
http 2.4.1 NameVirtualHost is no longer required and ServerName * is no longer supported.
Use ServerName * to report to Invalid ServerName "*" use ServerAlias set multiple server names.
Type 1: Outright rejection
Open httpd.conf and add the following code at the end of the file:
<pre name="code" class="html"><pre name="code" class="html"># Ban all illegal domain names
<VirtualHost *:80>
ServerName The server ip
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
<pre name="code" class="html"># The domain name to which access is allowed
<VirtualHost *:80>
DocumentRoot /alidata/www
ServerName 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 On
RewriteRule ^(.*)-htm-(.*)$ .php?
RewriteRule ^(.*)/simple/([a-z0-9\_]+\.html)$ /simple/index.php?
</IfModule>
# Error log save location
ErrorLog "/alidata/log/httpd/error.log"
CustomLog "/alidata/log/httpd/info.log" common
</VirtualHost>
Restart the apache service: service httpd restart
Type 2: Jumps to a specified directory or file
Open ES65en. conf and add the following code at the end of the file:
<pre name="code" class="html"><pre name="code" class="html"># Ban all illegal domain names
<VirtualHost *:80>
DocumentRoot "/alidata/www"
ServerName The server ip
ServerAlias *
<Location /alidata/www>
Order Allow,Deny
Allow from all
</Location>
</VirtualHost>
</pre>
<pre name="code" class="html"># The domain name to which access is allowed
<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>
# Error log save location
ErrorLog "/alidata/log/httpd/error.log"
CustomLog "/alidata/log/httpd/info.log" common
</VirtualHost>
Restart the apache service: service httpd restart