Basic Auth + PHP

Hi guys,
I’ve already been browsing this forum, but all other solutions don’t
work so far.

I have a simple nginx + fastcgi setup.

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
}

I now want the /admin/ directory, including all .php files, to be
secure, but couldn’t manage to do that. The rewrite tricks from older
threads didn’t work.

Anyone got a configuration example?

Thanks!

On Friday 25 July 2008, Bubulino Werty wrote:

    }

I now want the /admin/ directory, including all .php files, to be
secure, but couldn’t manage to do that. The rewrite tricks from older
threads didn’t work.

Anyone got a configuration example?

Thanks!

you need two additional locations
first one is “location /admin”
and second one (before location ~ .php$) “location ~ ^/admin/.+.php$”

yeah you have to nest the locations

            location /phpmyadmin {
                    auth_basic "phpMyAdmin";
               auth_basic_user_file /home/foo/.htpasswd;
                    location ~ \.php {
                            fastcgi_pass 127.0.0.1:11011;
                            fastcgi_index index.php;
                    }
            }

doesn’t seem like the cleanest way but oh well :slight_smile:

Thank you both!

I used Mike’s configuration and it worked just fine. It might be a bit
verbose, but that really isn’t a problem. I also found that that you
don’t have to specify a “root” directive for every location, but rather
you can have one for the whole server (should have read the docs more
thoroughly).

In any case, thanks again.