How can a WEB server built with Apache allow netizens to access only through the set domain name and not directly through the IP address of the server? There are two ways to achieve this (limited to what I know, of course there will definitely be other methods can be achieved), all are achieved by modifying the httpd.conf file, as shown below with examples.
Method 1: Add the following code at the end of the httpd.conf file
NameVirtualHost 221.*.*.*
<VirtualHost 221.*.*.*>
ServerName 221.*.*.*
<Location />
Order Allow, Deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost 221.*.*.*>
DocumentRoot "c:/web"
ServerName www.webjx.com
</VirtualHost>
Note: The blue part is to deny any access request directly through the IP 221.*.*.*. At this time, if you use 221.*.*.* to access, you will be prompted to deny access. The red part allows access through the domain name www.webjx.com, and the home directory points to c:/web (assuming here that the root directory of your website is c:/web)
Method 2: Add the following code at the end of the httpd.conf file
NameVirtualHost 221.*.*.*
<VirtualHost 221.*.*.*>
DocumentRoot "c:/test"
ServerName 221.*.*.*
</VirtualHost>
<VirtualHost 221.*.*.*>
DocumentRoot "c:/web"
ServerName www.webjx.com
</VirtualHost>
Note: The blue part points the direct access request through the IP address 221.*.*.* to the c:/test directory. This can be an empty directory, or you can create a homepage file in it, such as index.hmtl. The content of the file can be a statement stating that it cannot be accessed directly via IP. The meaning of the red part is the same as method one.
Note: You need to restart apache after modification