4

I did some coding to get the nginx config file working.

My objective is to allow all .well-known folder and subfolders leaving the rest with basic auth, limit_req and laravel compatible.

The problem now with let's Encrypt is that it is not renewing the cert because the route .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXM is asking for permission, probably affected by location ~ \.php$

So the question is: Can I integrate one solo function? like ~ / and \.php$ \.(?!well-known).* And if so, can I integrate the code of both all 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;
}

2 Answers 2

2

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 don't think it can be optimised

Sign up to request clarification or add additional context in comments.

Comments

2

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

Not sure if it can be optimised tho

1 Comment

looks good but the route .well-known/acme-challenge/wPCZZWAN8mlHLSQWr7ASZrJ_Tbk71g2Cd_1tPAv2JXM is not auth off

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.