Nginx RegEx to match a directory and file

Posted by HTF on Server Fault See other posts from Server Fault or by HTF
Published on 2012-10-22T21:22:09Z Indexed on 2012/10/22 23:04 UTC
Read the original article Hit count: 378

Filed under:
|

I'm wondering if it's possible to match Wordpress directory and specific file in the same location, so at the moment I've got rule to match only the wp-admin directory:

## Restricted Access directory
location ^~ /wp-admin/ {
        auth_basic            "Access Denied!";
        auth_basic_user_file  .users;

location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        }
        }

I would like to also match the wp-login.php file but I can't get to work, I've tried the following:

location ^~ /(wp-admin/|wp-login.php) {
...

© Server Fault or respective owner

Related posts about nginx

Related posts about regex