0

Trying to be clever and allow access depending on an environment variable. It doesn't seem to work (no errors, the expression is always false).


What I tried:

<VirtualHost *:80>

  ...

  <Directory /var/www/html>
    Options       Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order         allow,deny

    <If "reqenv('ENVIRONMENT_STATE') == 'dev'">
      allow from 1.22.333.0/24
      deny from all
    </If>
    <Else>
      allow from all
    </Else>
  </Directory>
</VirtualHost>

Expected behavior:

If ENVIRONMENT_STATE is set to 'dev', then restrict all access except from the mentioned IP.


Sources:

http://httpd.apache.org/docs/2.4/mod/core.html#else
https://httpd.apache.org/docs/2.4/expr.html

1 Answer 1

0

I would use the .htaccess file for IP restrictions. The reasons being:

  • You can source control it.
  • No server restart required when adding or removing IP addresses.
  • If you accidentally lock yourself out you can always FTP in and edit the file to restore access.

See this question for an example.

1
  • Thanks for taking the time to respond, but I'm not sure how this answered the question regarding the deny depending on the ENVIRONMENT_STATE variable value? Could you please elaborate?
    – superhero
    Oct 14, 2015 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .