Welcome! Log In Create A New Profile

Advanced

Protect a specific php file

January 12, 2012 11:21AM
Hello,

On my server I have a php app in a subfolder of my root, so basically I've made the following nginx configuration :


server {
listen 80;
server_name www.domain.fr;
root /var/www/domain.fr;
access_log /var/log/nginx/access.log ;
location /myapp {
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
}

And it's work now in this app I want to protect the index.php file and only this one, so I try this :


location /myapp {
location ^~ /myapp/index.php {
auth_basic "Private Section";
auth_basic_user_file $document_root/.htpasswd;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}

I had to duplicate the php location, is there an another way ?

It work with IE8 but not with Chrome !!

With Chrome the complete URL (http://www.domain.fr/myapp/index.php) is correctly protected but not this one http://www.domain.fr/myapp/
In this case the php file is downloaded...

Any idea why ? Any solution ?

Thanks a lot
Subject Author Posted

Protect a specific php file

voidandany January 12, 2012 11:21AM

Re: Protect a specific php file

António P. P. Almeida January 12, 2012 11:54AM

Re: Protect a specific php file

voidandany January 13, 2012 03:57AM

Re: Protect a specific php file

voidandany January 13, 2012 06:13AM

Re: Protect a specific php file

Francis Daly January 13, 2012 01:30PM

Re: Protect a specific php file

voidandany January 13, 2012 04:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 287
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready