Laravel + basic auth except for one folder not working

I did some encoding to get the nginx configuration file.

My goal is to allow all folders .well-knownand subfolders to leave the rest with basic auth, limit_req and laravel compatibles.

Now the problem with Encrypt is that it does not renew the certificate, because the route .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXMrequests permission, possibly affectedlocation ~ \.php$

So the question is: can I integrate one solo function? for example. ~ / and \.php$ \.(?!well-known).*And if so, can I combine the code together?

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;
}
+4
source share
2 answers

easy peasy

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

I do not think it can be optimized

+2
source

You can try the following:

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

,

+2

Source: https://habr.com/ru/post/1694969/


All Articles