Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to configure the Apache server to prohibit all illegal domain names from accessing your own server

Shulou Source: shulou.com Published: 2022-06-01 14:17:42 09月17日 Update

This article introduces the knowledge of "how to configure the Apache server to prohibit all illegal domain names from accessing your server". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Before http2.4.1:

The first one denies access directly.

Open the httpd.conf file and append the following configuration to the end of the file.

# directly reject all illegal domain names ServerName * ServerAlias * Order Allow,Deny Deny from all ErrorLog "/ alidata/log/httpd/error.log" CustomLog "/ alidata/log/httpd/info.log" common# allowed DocumentRoot / alidata/www ServerName www. Your domain name ServerAlias www. Your domain name Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all RewriteEngine On RewriteRule ^ (. *)-htm- (. *) $.php? RewriteRule ^ (. *) / simple/ ([a-z0-9\ _] +\ .html) $/ simple/index.php? ErrorLog "/ alidata/log/httpd/error.log" CustomLog "/ alidata/log/httpd/info.log" common

Restart the apache service: service httpd restart

The second type jumps to a specified directory or file

Open the httpd.conf file and append the following configuration to the end of the file.

# all illegal domain names jump to the specified directory or file # specified directory or file DocumentRoot "/ yun/www" ServerName * ServerAlias * # allowed domain name DocumentRoot / alidata/www/fdt ServerName www.fdt-art.com ServerAlias www.fdt-art.com Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all RewriteEngine On RewriteRule ^ (. *)-htm- (. *) $.php? RewriteRule ^ (. *) / simple/ ([a-z0-9\ _] +\ .html) $/ simple/index.php? # error log ErrorLog "/ alidata/log/httpd/error.log" CustomLog "/ alidata/log/httpd/info.log" common

Restart the apache service: service httpd restart

2. After http2.4.1:

Http2.4.1 no longer needs NameVirtualHost and does not support ServerName *.

Use ServerName * to report Invalid ServerName "*" use ServerAlias to set multiple server names.

The first one: direct refusal

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

# prohibit all illegal domain name ServerName server ip ServerAlias * Order Allow,Deny Deny from all # allowed access to the domain name DocumentRoot / alidata/www ServerName www. Your domain name ServerAlias www. Your domain name Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all RewriteEngine On RewriteRule ^ (. *)-htm- (. *) $.php? RewriteRule ^ (. *) / simple/ ([a-z0-9\ _] +\ .html) $/ simple/index.php? # error log location ErrorLog "/ alidata/log/httpd/error.log" CustomLog "/ alidata/log/httpd/info.log" common

Restart the apache service: service httpd restart

Second: jump to a specified directory or file

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

# prohibit all illegal domain names DocumentRoot "/ alidata/www" ServerName server ip ServerAlias * Order Allow,Deny Allow from all # allowed access to the domain name DocumentRoot / alidata/www/fdt ServerName www.fdt-art.com ServerAlias www.fdt-art.com Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all RewriteEngine On RewriteRule ^ (. *)-htm- (. *) $.php? RewriteRule ^ (. *) / simple/ ([a-z0-9\ _] +\ .html) $/ simple/index.php? # error log location ErrorLog "/ alidata/log/httpd/error.log" CustomLog "/ alidata/log/httpd/info.log" common

Restart the apache service: service httpd restart

This is the end of the content of "how to configure the Apache server to prohibit all illegal domain names from accessing your own server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Domain name service file server configuration directory log error code location content more end knowledge utility achievement next writing dilemma reality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Xiaomi Shulou Technology Apple