I could not find the information on the web or in the wiki, so I try
this list. I am the user of a free hosting service using nginx. So I
cannot acces or edit conf files myself, but I can ask the admin and he
will do it for me.
Basically, I want to protect whole folders. I think that I have managed
to do that by asking the admin to add these lines to the nginx.conf
file:
This does protect all files in folder1 and folder2. However, after
entering the password, instead of seeing the index.php file display the
page on screen, my browser pops up this download dialogue:
I could not find the information on the web or in the wiki, so I try this list. I am the user of a free hosting service using nginx. So I cannot acces or edit conf files myself, but I can ask the admin and he will do it for me.
Basically, I want to protect whole folders. I think that I have managed to do that by asking the admin to add these lines to the nginx.conf file:
This is the expected behavior. I would guess that your configuration
file contains a different location block for handling files with a
“.php” extension. In this case nginx will only match one location. See Module ngx_http_core_module.
To avoid serving the index.php file as a text file you can try using
nested location blocks. This is an undocumented feature and can have
unpredictable results, but in this case I guess it will work OK.
Try something like:
location ~ /srv/www/users/me/(folder1|folder2)/.* {
auth_basic “Restricted”;
auth_basic_user_file /srv/www/users/me/folder1/.htpasswd;
location ~.php {
fastcgi_pass 127.0.0.1:9000; # substitute here with appropriate PHP
backend address or proxy_pass statement and parameters.
…
}
}
Posted at Nginx Forum:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.