我做了一些编码以使 nginx 配置文件正常工作。
我的目标是允许所有 .well-known
文件夹和子文件夹,其余的与基本身份验证、limit_req 和 laravel 兼容。
let's Encrypt 现在的问题是它没有更新证书,因为路由 .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXM
正在请求权限,可能受 location 影响~\.php$
所以问题是:我可以集成一个 solo 函数吗?像 ~/和\.php$\.(?!well-known).*
如果是这样,我可以将两者的代码整合在一起吗?
location ~ /\.(?!well-known).* {
limit_req zone=admin burst=5 nodelay;
limit_req_status 503;
try_files $uri $uri/ /index.php?$query_string;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
最佳答案
简单易行
location / {
limit_req zone=admin burst=5 nodelay;
limit_req_status 503;
try_files $uri $uri/ /index.php?$query_string;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
}
location ^~ /.well-known/ {
auth_basic off;
}
我觉得没法优化
关于php - Laravel + 基本身份验证,除了一个文件夹不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49321450/