Apache Prohibit IP Access implementation method

Source: Internet
Author: User
Tags access address apache code course directory domain domain name

With Apache Web server, how to let users only through the set domain name access, and not directly through the server's IP address access it, there are two ways to achieve (only I know, of course, there will be other ways to achieve), are modified httpd.conf files to implement, as illustrated below.

Method One: At the end of the httpd.conf file, add the following code

Namevirtualhost 221.*.*.*
<virtualhost 221.*.*.*>
ServerName 221.*.*.*
<location/>
Order Allow,deny
Deny from all
</Location>
</VirtualHost>
<virtualhost 221.*.*.*>
DocumentRoot "C:/web"
ServerName www.jzread.com
</VirtualHost>

Description: The blue part is to implement any access request that refuses to 221.*.*.* this IP directly, then if you use 221.*.*.* access, you will be prompted to deny access. The red section is to allow access through the www.jzread.com domain name, and the home directory points to C:/web (assuming that your site's root directory is c:/web)

Method Two: At the end of the httpd.conf file, add the following code

Namevirtualhost 221.*.*.*
<virtualhost 221.*.*.*>
DocumentRoot "C:/test"
ServerName 221.*.*.*
</VirtualHost>
<virtualhost 221.*.*.*>
DocumentRoot "C:/web"
ServerName www.jzread.com
</VirtualHost>
    
Description: The blue part is to pass 221.*.*.* this IP direct access to the request to the C:/test directory, this can be an empty directory, you can also build a home page file, such as INDEX.HMTL, the first file content can be a declaration, the description cannot be directly accessed via IP. The red part means the same as the method.

Note: Restart Apache after modification

Related Article

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.