Restrict sub-directory access divert if not authenticated

I am moving from a development server to a live server and would like to
still test before REALLY going live.

I need to redirect access to a sub-folder until I am satisfied with the
stability

this is what i have:

server {
listen 80;
server_name hostname.com

#other configurations

location ~ \.php$ {
    #fastcgi configurations
}

now for the new sub-site

location /shop/ {
    # I would like to redirect to ShopSoonToOpenAdvertisement.html 

if
deny
satisfy any;
allow 203.0.0.133; # my testing server and some client’s ip’s for
testing
deny all;
auth_basic “sorry but this page is off limits - please go back to
hostname.com”;
auth_basic_user_file /etc/nginx/.htpasswd;
}
}


for this config the server does not allow access to hostname.com/shop/

but

hostname.com/shop/index.php

will render the page sans the .js, css, etc…

I would like to show the shop if passw or allow is satisfied else
redirect
to a static html file

Any suggestions??

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257266,257266#msg-257266

16.03.15 8:11, jacograaff пишет:

 server_name hostname.com
 location /shop/ {

}


for this config the server does not allow access to hostname.com/shop/

but

hostname.com/shop/index.php

will render the page sans the .js, css, etc…

So you say that /shop/index.php doesn’t land to /shop/ location? Then
ensure that you don’t have location /shop/index.php , otherwise see
debug log

I would like to show the shop if passw or allow is satisfied else redirect
to a static html file

error_page 401 403 /ShopSoonToOpenAdvertisement.html;


br,
Dmitry Pryadko

Hi thanks for that

your suggestion:

So you say that /shop/index.php doesn’t land to /shop/ location? Then
ensure that you don’t have location /shop/index.php , otherwise see
debug log

I do want access to /shop/ as well as /shop/index.php - but only to a
select
ip-range or password

my directive works for /shop/

but if someone types in /shop/index.php they will see the index.php page
since the directive for php files overwrites the shop subfolder
directive.

They see the php file but the html, js, css, img resources does not load
because those do still obey my “location /shop/” directive

I guess I have to either

  1. declare as: “location /shop/ ~ .php$”

or

  1. inside the location “/shop/” directive have a clause to force php not
    to
    obey the above “location ~ .php$” directive

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257266,257293#msg-257293

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs