Apache restrict access based on IP address to selected directories
Apache web server allows server access based upon various conditions. For example you just want to restrict access to url http://payroll.nixcraft.in/ (mapped to /var/www/sub/payroll directory) from 192.168.1.0/24 network (within intranet).
Apache provides access control based on client hostname, IP address, or other characteristics of the client request using mod_access module.
Open your httpd.conf file:
# vi /etc/httpd/conf/httpd.confLocate directory section (for example/var/www/sub/payroll) and set it as follows:Where,
<Directory /var/www/sub/payroll/>
Order allow,deny
Allow from 192.168.1.0/24
Allow from 127
</Directory>
- Order allow,deny: The Order directive controls the default access state and the order in which Allow and Deny directives are evaluated. The (allow,deny) Allow directives are evaluated before the Deny directives. Access is denied by default. Any client which does not match an Allow directive or does match a Deny directive will be denied access to the server.
- Allow from192.168.1.0/24: The Allow directive affects which hosts can access an area of the server (i.e. /var/www/sub/payroll/). Access is only allowed from network 192.168.1.0/24 and localhost (127.0.0.1).
Save file and restart apache web server:
# /etc/init.d/httpd restart
See also
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Restrict ssh access using Iptable
- How To Secure Apache Proxy Server (mod_proxy)
- Apache name based VirtualHost example
- Restrict ssh access using tcpd (TCPWrapper)
- Lighttpd virtualhost configuration ~ name-based virtual hosting
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: access control, access module, apache allow access, apache deny directory access, apache web server, httpd, ip address, restrict access



Recent Comments
Yesterday ~ 1 Comment
Yesterday ~ 3 Comments
Yesterday ~ 2 Comments
Yesterday ~ 3 Comments
Yesterday ~ 13 Comments