php - Laravel + 基本身份验证,除了一个文件夹不起作用

标签 php laravel nginx

我做了一些编码以使 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/

相关文章:

php - 如何在文本框中删除自动完成

php - Eloquent ORM 电影取景地

php - 如何在 php 测试中使用模拟对象

nginx - 使用 Nginx 部署多个 Go 应用程序

django - 504网关超时uwsgi + nginx Django应用程序

php - CakePHP 更改列表输入中的格式

php - 机器人提交表单的方式与使用浏览器的方式不同吗?

laravel - 使用 laravel 显示当月注册用户列表

javascript - 在 Nginx 代理后面刷新页面后,我的 Angular 6 路由返回 404

PHP strtotime 将 false 保存为 MySQL 负整数