I’m trying to restrict access to a particular directory within my DigitalOcean Droplet and I’m unsure how to get it working. I’ve never had to do anything like this before so I’m googling all options and trying anything out at the moment.
The main folder the content is in is allowed to be accessed by any IP address but a particular folder within that directory and all of its contents needs to be restricted so only one IP can view it.
The DigitalOcean Droplet is running LAMP on Ubuntu 22.04 (Apache 2.4).
I first tried to use an .htaccess file to do this but not sure if there’s any other setup I’m meant to do in this file:
<RequireAll>
Require ip xxx.xxx.xxx.xxx
</RequireAll>
I then looked at adding some info to the conf file that I have set up (as I’m using virtual hosts) but again this hasn’t worked:
Location: /etc/apache2/sites-available/dev-tools.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName dev.test
ServerAlias dev.test
DocumentRoot /var/www/dev-tools
ErrorLog ${APACHE_LOG_DIR}/dev-tools/error.log
CustomLog ${APACHE_LOG_DIR}/dev-tools/access.log combined
<Directory /var/www/dev-tools/restricted-folder>
Require ip xxx.xxx.xxx.xxx
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =dev.test
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I realise I need to check that I have loaded the authz_core module in order to use the above in my dev-tools.conf file but I’m not entirely sure how to do that…
Any help on this would be gladly appreciated!