【问题标题】:Laravel + basic auth except one folder not workingLaravel + 基本身份验证,除了一个文件夹不起作用
【发布时间】:2018-08-25 13:30:03
【问题描述】:

我做了一些编码来让 nginx 配置文件正常工作。

我的目标是允许所有 .well-known 文件夹和子文件夹保留其余的基本身份验证、limit_req 和 laravel 兼容。

现在 let's Encrypt 的问题是它没有更新证书,因为路由 .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXM 正在请求许可,可能受到 location ~ \.php$ 的影响

所以问题是:我可以集成一个独奏功能吗?比如~ / and \.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;
}

【问题讨论】:

    标签: php laravel nginx


    【解决方案1】:

    简单易懂

    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;
        }
    

    我不认为它可以优化

    【讨论】:

      【解决方案2】:

      您可以尝试以下方法:

      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;
      }
      
      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/ {
          allow all;
          auth_basic off;
      }
      

      不确定是否可以优化

      【讨论】:

      • 看起来不错,但路线 .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXM 未关闭身份验证
      猜你喜欢
      • 2014-12-31
      • 1970-01-01
      • 2014-09-06
      • 2014-01-22
      • 2016-01-11
      • 2023-02-24
      • 2020-02-09
      • 2016-10-21
      相关资源
      最近更新 更多