简体   繁体   中英

Nginx Basic Auth and subfolders

I have a problem with subfolders in a basic auth procted folder. In the protected folder i have a folder named phpmyadmin, which contains phpmyadmin. Im not able to run phpmyadmin, when basic is activated. Whenn i call the the folder, i get a save-as dialog (type: application/octet-stream (18,3 KB)).

Here the important parts of mysites-available/default

location ^~ /administration/ {
    auth_basic            "Restricted Area";
    auth_basic_user_file  /var/www/myproject/sec/htpasswd;
}

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Any ideas, how i can run php in basic-auth protected subfolders?

You could just repeat the location ~ \\.php$ block inside the /administration/ block.

As a workaround, I've also used this setup with success, which saves me from repeating the PHP configuration over and over in complex scenarios.

location ^~ /administration/ {
    auth_basic            "Restricted Area";
    auth_basic_user_file  /var/www/myproject/sec/htpasswd;
    location ~ \.php$ {
        try_files /dummy/$uri @php;
   }
}

location ~ \.php$ {
    try_files /dummy/$uri @php;
}

location @php {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

It basically uses a named location for the PHP configuration. Unfortunately you can not use such a location everywhere. But it works with try_files . You should make sure, that there's no directory /dummy/ on your server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM