【发布时间】:2021-10-12 20:36:10
【问题描述】:
我开发了一个 Laravel 应用程序,通过 Laravel Forge 部署了一个暂存版本,并为所有工作正常的位置设置了基本身份验证。我需要从一个位置删除基本身份验证,但很难做到这一点。根据 Forge 的文档:
Nginx allows you to add further access restrictions such as allowing and
denying access to users by IP address. Forge does not provide the ability
to configure this, but you are free to customize your own protected site
configuration. Forge creates a
/etc/nginx/forge-config/.../server/protected_site-{ruleId}.conf
configuration file for protected sites.
所以 Forge 将在所述文件中创建:
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/forge-conf/staging.mysite.com/server/.htpasswd-21495;
我希望通过执行以下操作来修改从一条路径中删除基本身份验证:
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/forge-conf/staging.mysite.com/server/.htpasswd-21495;
location /my-unrestricted-uri {
auth_basic off;
}
当 nginx 配置文件放在一起时,它会产生以下结果(我已经截断了它,但希望包括所有相关部分):
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
...
location / {
try_files $uri $uri/ /index.php?$query_string;
}
...
}
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/forge-conf/staging.mysite.com/server/.htpasswd-21495;
location /my-unrestricted-uri {
auth_basic off;
}
使用上面的配置,我仍然收到“401 - 需要授权”。我怎样才能打开这个 uri?
编辑:经过一番修修补补,我想我已经走得更远了。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
...
location / {
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/forge-conf/staging.mysite.com/server/.htpasswd-21495;
try_files $uri $uri/ /index.php?$query_string;
location = /my-unrestrcited-uri {
auth_basic off;
try_files $uri $uri/ /index.php?$query_string;
}
}
...
}
#auth_basic "Restricted Area";
#auth_basic_user_file /etc/nginx/forge-conf/staging.mysite.com/server/.htpasswd-21495;
#location /my-unrestricted-uri {
# auth_basic off;
#}
所以我已将基本身份验证请求移至位置块,并使用子位置关闭基本身份验证。该路由现在不受保护,这正是我想要的,但是在访问站点的任何其他部分时,我不断被要求提供身份验证凭据,因此这里发生了某种重定向循环。
【问题讨论】:
标签: laravel nginx laravel-forge