Restrict access to your Apache Virtual Host

In some case you need to restrict your virtual host site by IP address. Usually the type of site that handle important information such as Administrator site or web-based database administration site (eg : phpMyAdmin) or else. For example the admin site of your website can be accessed only in Office network. This Apache configuration below may helps you.

<VirtualHost *:80>
    DocumentRoot /path/to/website/admin
    ServerName admin.ariawan.web.id

    <Location />
          Order Deny,Allow
          Deny from all
          Allow from 202.204.9.24
    </Location>

</VirtualHost>

The IP address above is your public IP address of your office. Beside <Location>, you also can use the other Apache directive <Directory>.

You can see the complete documentation of configuration sections containers in Apache, that may be suits your need. Here is the link http://httpd.apache.org/docs/current/sections.html

Yup. That’s all.

Leave a Reply

Your email address will not be published. Required fields are marked *