gpt4 book ai didi

wordpress - Nginx 忽略 WordPress 登录目录的 HTTP 身份验证

转载 作者:可可西里 更新时间:2023-11-01 16:38:04 26 4
gpt4 key购买 nike

我在我的域的子文件夹中运行 WordPress,以便在 VPS LEMP 堆栈上进行测试和开发。为了使用 etxra 层对 wp-login.php 进行密码保护,我对 wp-admin 文件夹使用了 HTTP 身份验证。

问题是http认证被忽略了。当 wp-login.php 或 wp-admin-folder 被调用时,它直接进入正常的 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,而不是转到主登录屏幕。

你能告诉我如何解决这个问题吗?

最佳答案

问题是旧位置 block 不会将 PHP 配置传递给新 block ,因此不会处理 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;
}

关于wordpress - Nginx 忽略 WordPress 登录目录的 HTTP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21312527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com