我正在域的子文件夹中运行wordpress,以便在vps lemp堆栈上进行测试和开发。为了使用etxra层对wp-login.php进行密码保护,我对wp-admin文件夹使用了http身份验证。
问题是忽略了http身份验证。当wp-login.php或wp admin文件夹被调用时,它将直接转到普通的wordpress登录。
我按照以下方式安装了命令行中的所有内容:

sudo apt-get install apache2-utils

sudo htpasswd -c /var/www/bitmall/wp-admin/.htpasswd exampleuser

New password:
Re-type new password:
Adding password for user exampleuser

我的nginx配置文件如下所示:
server {
    listen   80;


    root /var/www;
    index index.php index.html index.htm;

    server_name eample.com;

    location / {
            try_files $uri $uri/ /index.html;
    }

location /bitmall/wp-admin/ {
    auth_basic "Restricted Section";
    auth_basic_user_file /var/www/bitmall/wp-admin/.htpasswd;
}

location ~ /\.ht {
    deny all;
}

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /var/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }

}

我已经尝试过按照下面的question更改nginx配置:
location ~* (wp-login)\.php$ {
            auth_basic            "Restricted Area";
            auth_basic_user_file  /var/www/bitmall/.htpasswd;
    }

此代码将调用http身份验证,但当输入凭据时,浏览器将下载wp-login.php,而不是转到主登录屏幕。
你能告诉我怎么解决这个问题吗?

最佳答案

问题是旧的location块没有将php配置传递给新的块,因此php请求不会被处理。下面解决了这个问题:

location ~* /wp-login.php {
            auth_basic "Restricted Area";
            auth_basic_user_file PATH TO .htpasswd;

            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

07-26 09:41