80 likes | 93 Views
Sometimes you may need to restrict access to URL, file or directory. Here is how to deny access to URL, Files & Directory in Apache.<br><br>Visit https://ubiq.co/tech-blog/apache-deny-access-to-url-files-directory/
E N D
Open Apache Configuration File Apache configuration file is located at one of the following locations, depending on your Linux distribution. • /etc/apache2/httpd.conf • /etc/apache2/apache2.conf • /etc/httpd/httpd.conf • /etc/httpd/conf/httpd.conf Open terminal and run the following command to open Apache configuration page. $ sudo vi /etc/httpd/conf/httpd.conf
Restrict Access by IP (⅓) Let us assume you want to limit access to /product.html URL by IP 45.34.21.10. Once you have opened the appropriate configuration file, look for <Location> tag for the above URL. Apache provides Deny directive to block one or more IP addresses. Add the following line in Location tag Deny 45.34.21.10
Restrict Access by IP (⅔) If you want to block IP from accessing a specific directory such as /admin, then add the above Deny directive location block of /admin subfolder. <Location /admin> ... Deny 45.34.21.10 ... </Location>
Restrict Access by IP (3/3) If you want to block IP from accessing a specific file such as /var/www/html/input.html, then add the above Deny directive in Directory block of input.html file. <Directory /var/www/html/input.html> ... Deny 45.34.21.10 ... </Directory>
Apache Limit Access by multiple IP If you want to limit access to multiple IPs, add separate Deny directives for each IP. In the following example, we limit access to IPs 45.34.21.10 and 65.34.23.12 <Location /product.html > ... Deny 45.34.21.10 Deny 65.34.23.12 ... </Location>
Restart Apache web server Restart Apache web server to apply changes. # service httpd restart OR # systemctl restart httpd OR # sudo service apache2 restart
Thank You Visit for details https://ubiq.co/tech-blog/apache-deny-access-to-url-files-directory/