Apache prohibits IP access

Source: Internet
Author: User

For a WEB server built with apache, there are two ways to allow users to access the server only through the specified domain name instead of the IP address of the server, of course there will certainly be other methods that can be implemented), are modifying httpd. conf file. The following is an example.

Webpage Tutorial network


Method 1: Add the following code at the end of the httpd. conf file:

Webpage Tutorial network

NameVirtualHost 221 .*.*.*
<VirtualHost 221. *>
Server name 221 .*.*.*
<Location/>
Order Allow, Deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost 221. *>
DocumentRoot "c:/web"
ServerName
</VirtualHost>

Note: the blue part is used to reject the request directly through 221. *. *. * for any access request from this IP address, if you use 221. *. *. * access is denied. The red part allows access through this domain name. The main directory points to c:/web (assume that the root directory of your website is c:/web)

Webpage Tutorial network

Method 2: Add the following code at the end of the httpd. conf file:

NameVirtualHost 221 .*.*.*
<VirtualHost 221. *>
DocumentRoot "c:/test"
Server name 221 .*.*.*
</VirtualHost>
<VirtualHost 221. *>
DocumentRoot "c:/web"
ServerName www.111cn.net </VirtualHost>

Note: the blue part passes through 221. *. *. * direct access requests from this IP address point to the c:/test Directory. This can be an empty directory or a home page file, such as index, can be created. hmtl. The content of the first file can be a declaration, indicating that it cannot be accessed directly through an IP address. The red part means the same as method 1.

Webpage Tutorial network

Note: restart apache after modification.

Method 2

Method 1: Create a VM,

ServerName IPAddress (for example, 192.168.0.1)

DocumentRoot/usr/local/apache/nosite/

In this way, you can.

Create an index.htm under/usr/local/apache/nosite/and prompt the user that IP access is not allowed. Or other error messages.

Method 2:

ServerName IPAddress (for example, 192.168.0.1)

DocumentRoot/usr/local/apache/nosite/

Order deny, allow

Deny from all

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.