Generally, websites can be accessed by domain names and IP addresses. Your website can be accessed directly through an IP address. This is no problem, but it may cause some risks:
Because the search engine will also include the pages of your IP address, the same page search engine will record the pages, resulting in a higher page weight than a single index.
The possibility of malicious domain name pointing. Do you still remember the google.com. sb incident last year or the year before? The domain name google.com. sb was maliciously directed to Baidu, and later confirmed that the domain name google.com. sb was maliciously pointed to by a third party, not by Google. Of course this is just a joke, but if someone maliciously uses another domain name to resolve your IP address, then your website will be accessible through another domain name. What will happen next? If the domain name is unfriendly, for example, if it has been directed to an illegal website, it is easy to cause search engine penalties and the IP address is associated. Even if there is no problem with the domain name, the traffic will be hijacked to another domain name, thus being banned by the advertising alliance.
How can this problem be solved? The most direct method is to allow users to access the website only through the domain name, but not through the IP address. This can be implemented by modifying the Apache configuration file httpd. conf. The following is the implementation of the station:
1. NameVirtualHost 121.*.*.*
2. <VirtualHost 121.*.*.*>
3. ServerName 121.*.*.*
4. <Location />
5. Order Allow,Deny
6. Deny from all
7. </Location>
8. </VirtualHost>
9. <VirtualHost 121.*.*.*>
10.DocumentRoot /var/www/nowamagic/
11.ServerName www.nowamagic.net
12.</VirtualHost>
13.<VirtualHost 121.*.*.*>
14.DocumentRoot /var/www/nowamagic/
15.ServerName nowamagic.net
16.</VirtualHost>
The first part of the code is to reject any access requests directly through the IP address 121. *. If you use 121. *. * for access, a message is displayed, prompting you to reject the access.
The second part of the code is to allow access through the http://www.nowamagic.net/this domain name, the main directory points to/var/www/nowamagic/(here the Server OS is CentOS ).
The third part of the code is to allow access by domain names without www. You should be able to write it together with the above Code.
Record it here to make it easy for you to stick to it later.