gpt4 book ai didi

htpasswd 身份验证后,php 文件不会呈现

转载 作者:行者123 更新时间:2023-12-01 20:04:46 25 4
gpt4 key购买 nike

我正在 nginx 服务器上运行 magento。我决定使用 auth_basic 和 htpasswd 文件锁定一个充满 .php 文件的文件夹。如果没有身份验证,php 页面将呈现并正常工作。但是在强制身份验证之后,当我进入该页面时,我收到登录提示(这很好),我登录,然后浏览器尝试下载 php 文件。它拒绝渲染它。这是跨多个浏览器(chrome、firefox、opera、ie)的。知道我需要做什么才能让它受到密码保护但仍然可以工作吗?谢谢!

编辑:.conf 文件身份验证设置

location ~^ /FOLDER/ {
auth_basic "Restricted";
auth_basic_user_file /path/to/htpasswd/;
}

最佳答案

Nginx 不会“跳转”到另一个位置,因此您必须将“代理”添加到 protected 位置内的 php 解释器进程:

location ~^ /FOLDER {
auth_basic "Restricted";
auth_basic_user_file /path/to/htpasswd/;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}

将端口或配置更改为配置其他位置中的任何内容。还有另一种命名位置的方法,但我认为您在这里不需要它。

关于htpasswd 身份验证后,php 文件不会呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26518812/

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