0

I'm setting up letsencrypt for two different domains: example.be and example.com

I've got Nginx configured to redirect all example.com/* requests to example.be/de/*

// Block 1
server {
    listen 80;
    server_name .example.com;
    return 302 http://example.be/de$request_uri;
}

// Block 2
server {
    listen 80;
    server_name www.example.be;
    return 302 http://example.be$request_uri;
}

Block 3
server {
    listen 80;
    server_name example.be;

    // server config
}

Eventually everything should land on Block 3. Except for the .well-known requests letsencrypt makes to .example.com The 302's are there temporary; after everything works they go to 301.

So I thought of 'catching' that uri in the first server block.

// rewrite of Block 1
server {
   listen 80;
   server_name .example.com;

   location ^~ /.well-known/ {
     root        /path/to/public/folder/;
     try_files   $uri =404;
   }

  return 302 http://example.be/de$request_uri;
}

A request to http://example.com/.well-known/test.html results in a redirect to http://example.be/de/.well-known/test.html

If I remove the return statement, the test.html page is displayed.

Any pointers in how to catch this request for .well-known directory?

0

I don't see why you've used ^~ in your location. It's not necessary. Try removing it.

My working certbot configuration is:

server {
        server_name www.yes-www.org yes-www.org www.yes-www.com yes-www.com;

        listen [::]:80;
        listen 80;

        location /.well-known/acme-challenge/ {
            root /var/www;
            try_files $uri =404;
        }

        access_log off;

        return 301 https://$host$request_uri;
}

If that doesn't work, try removing everything else from your server block that is present but that you might not have posted in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.