【发布时间】:2021-08-24 22:00:38
【问题描述】:
我们有 Nginx 并使用它来服务于 Laravel 8 项目
我需要通过基本身份验证来保护这个演示项目。
它可以工作,使用 nginx 和 auth_basic_file 指令
auth_basic "My DEMO";
location ~ ^/(api|public|images)/.* {
auth_basic off;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
# Protect access
auth_basic_user_file /etc/nginx/auth/.htpasswd;
add_header X-Dovesono-php 1;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
我的目标
我需要让 /api/ 实际上,使用上述配置,浏览器会在每次对 /api/ 的 ajax 调用时要求我进行身份验证。
此外,即使插入正确的用户名和密码,它也会无限期地重新询问问题
【问题讨论】:
标签: php laravel nginx http-authentication