4

I want to be able, if the request tries to access <host>/.well-known/acme-challenge/ to serve the matching file if found.

If the request is something else, I want to redirect it to https://

server { listen 8080; server_name my_example.com; location /.well-known/acme-challenge/ { alias /var/www/encrypt/.well-known/acme-challenge/; try_files $uri =404; } return 301 https://$server_name$request_uri; } 

Problem is when accessing to my_example.com/.well-known/acme-challenge/12345 which exist in alias path, i'm still redirected to https:// and the browser doesn't download the file.

How can I just serve the file and not apply the redirection in this case ?

Thanks

1
  • EXACTLY the same setup as us Commented Jan 15, 2018 at 15:35

1 Answer 1

5

Place the return statement inside a location block:

For example:

server { listen 8080; server_name my_example.com; location /.well-known/acme-challenge/ { root /var/www/encrypt; } location / { return 301 https://$server_name$request_uri; } } 

Also, simplified your other location block.

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

3 Comments

your location suggestion / will match all other request right ?
@sf_tristanb Yes, you can think of it as the default location block.
Thank you @Richard Smith

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.