5

I have an Apache server that, for the time being, I need to block access to for all but a select group of people. The easiest way to do this, I thought, would be to deny access from all traffic and then allow only the select few IP addresses. From what I have found online, this configuration should do the trick.

This is the entire contents of /etc/apache2/sites-available/000-default.conf:

    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html

            <Directory /var/www/html>
                    Order allow,deny
                    Deny from all
                    Allow from my.ip.add.res
            </Directory>

            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

However, when I test it, I get 403'd from everywhere, including the allowed "my.ip.add.res" IP address.

I've spent quite a lot of time Googling, but from what I can tell, this should work perfectly. Not sure why it isn't. Am I missing something obvious?

  • First of all, are you using Apache 2.4, as indicated in your tag, or are you using Apache 2.2, as indicated by the access control directives in your v-host configuration? – Colt May 12 '16 at 1:20
6

If you are using Apache 2.4, make sure that you LOAD the authz_core module,

DELETE:

Order allow,deny
Deny from all
Allow from my.ip.add.res

and, in place of the deleted directives,

INSERT:

Require ip xxx.xxx.xxx.xxx

If you are using Apache 2.2, make sure that you LOAD the authz_host module,

DELETE:

Order allow,deny
Deny from all
Allow from my.ip.add.res

and, in place of the deleted directives,

INSERT:

Order Deny,Allow
Deny from all
Allow from xxx.xxx.xxx.xxx
| improve this answer | |
  • Ah, that's it. I had no idea that the directives had changed from 2.2 to 2.4 (and I didn't do the initial install of this machine). Thanks heaps! – BSnapZ May 12 '16 at 1:56
  • I have apache 2.4.7 and I tried using the first way you showed but I get You don't have permission to access / on this server. I got my ip address from this website whatismyipaddress.com <Directory /var/www/stage/> Require ip 77.138.205.207 </Directory> Why can't I access it? – Offir Pe'er Oct 18 '18 at 9:26
  • @OffirPe'er you need to ask your own separate question after reading the Help Section on asking questions. You can link to this answer if it helps ask your new question, but you need to (1) have your own question so that the whole community sees and help with it, and (2) include your own particular details in that question. – Colt Oct 18 '18 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.