In a previous question, I was trying to password protect my /admin/ and sub-folders directory using Nginx with .htpasswd and regex.
That was done successfully, but now, after password authentication was completed, Nginx prompts to "download" php files, rather than simply loading them.
This doesn't happen when the new location "authentication" block is commented out. For instance, in this code sample, PHP pages load without any issue:
location / {
try_files $uri $uri/ =404;
}
#location "~^/admin/.*$" {
# try_files $uri $uri/ =404;
# auth_basic "Restricted";
# auth_basic_user_file /etc/nginx/.htpasswd;
#}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
How can I resolve these (apparently conflicting) location blocks, so the /admin/ section is password protected yet php files still load?