我在 VPS LEMP-stack 上为测试和开发目的在域的子文件夹中运行 WordPress。为了使用wp-login.php
etxra 层进行密码保护,我对 wp-admin 文件夹使用了 HTTP 身份验证。
问题在于 http 身份验证被忽略了。调用wp-login.php
orwp-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 example.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;
}
}
我将非常感激您对此的建议。
答案1
尝试:
location ^~ /bitmall/wp-login.php {
auth_basic "Restricted Section";
auth_basic_user_file /var/www/bitmall/wp-admin/.htpasswd;
}