0

I'm trying to get a password protected folder setup on my server (using nginx). I have tried it like so:

    location / {
        root   /srv/www/steampunkjunkies.net/www;
        index  index.html index.htm index.php;
    }

    location /cgi-bin/admin {
        satisfy any;
        allow  81.174.134.133;
        deny   all;
        auth_basic "Administrator Login";
        auth_basic_user_file /var/www/steampunkjunkies.net/htpasswd;
    }

...but the problem with that, is that once you login - it doesn't execute this code a bit further down:

    location ~ \.cgi$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /srv/www/steampunkjunkies.net/www/cgi-bin/$fastcgi_script_name;
    }

(so you just get a file download)

I'm at a bit of a loss as to what to do. Any suggestions? (this is my first time password protecting a folder on Nginx... but I've done it a ton of times on Apache)

UPDATE: As per a suggestion, I've now got:

location /cgi-bin/admin {
    satisfy any;
    allow  81.174.134.xxx;
    deny   all;
    auth_basic "Administrator Login";
    auth_basic_user_file /var/www/mysite.net/htpasswd;

    location ~ \.cgi$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /srv/www/mysite.net/www/cgi-bin/$fastcgi_script_name;
    }
}

The IP part works fine:

    satisfy any;
    allow  81.174.134.xxx;
    deny   all;

(if I change the IP to something that is not mine, then I get the popup... otherwise it lets me in ok)

The problem is with the popup password auth box. I enter the details (correctly), and it then goes away - but I'm then presented with a 403 Forbidden error for some reason. Any ideas?

1 Answer 1

0

The problem here is that all location blocks are separate here, and nginx selects the location based on first match.

You can solve the issue by including the location ~ \.cgi$ { block inside the location /cgi-bin/admin { block too, like this:

location /cgi-bin/admin {
    satisfy any;
    allow  81.174.134.133;
    deny   all;
    auth_basic "Administrator Login";
    auth_basic_user_file /var/www/steampunkjunkies.net/htpasswd;
    location ~ \.cgi$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /srv/www/steampunkjunkies.net/www/cgi-bin/$fastcgi_script_name;
    }
}
1
  • Kikanen Thanks. That almost works. For some reason, after entering the correct user/pass, it then presents me with a 403 error (please see my revise OP to see the current code I'm using). Jul 18, 2015 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .