Page 1 of 1

Nginx password protect directory

Posted: Wed Sep 09, 2015 1:06 pm
by prxbl
Hi,
I am trying to password protect a directory on my server with Nginx + Apache.
I have added the following lines to /home/admin/conf/web/nginx.conf inside the server { } definition.

Code: Select all

 location ~ ^/secret {
        root     /home/admin/web/domain.com/public_html;
        auth_basic "Administrator Login";
        auth_basic_user_file /home/admin/web/domain.com/public_html/secret/.htpasswd;
The directory is now password protected, however php files inside the directory are downloaded instead of executed when accessing them.

What am I missing there to tell Nginx to forward php requests as it should? and by "as it should" I mean like it does in the default config for document root.

Thanks

Re: Nginx password protect directory

Posted: Wed Sep 09, 2015 3:05 pm
by tjebbeke
I think you're trying to run php files through nginx, which is not possible. Protect your folder via apache (.htaccess).

Re: Nginx password protect directory

Posted: Wed Sep 09, 2015 3:08 pm
by prxbl
It is possible, I just need the right config instructions to tell Nginx how to process php files.
Protecting my folder via Apache is not a solution because Nginx is the main web server here.

I can find many example of configuring nginx for php5-fpm or FastCGI but I'm not sure how VestaCP is doing it so I don't want to risk breaking my whole setup, that's why I am asking here to get direction on how to do it the same way VestaCP is handling it.

Re: Nginx password protect directory

Posted: Thu Sep 10, 2015 7:07 am
by tjebbeke
Nginx is used as a kind of proxy. You must protect the directory via apache.

nginx - php-fpm support is comming in next release.