Nginx location alias + redirect
I want to be able, if the request is trying to access <host>/.well-known/acme-challenge/
, to serve the corresponding 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;
}
The problem is that when accessing the my_example.com/.well-known/acme-challenge/12345
aliases that exist in the path, I am still redirected to https: // and the browser does not download the file.
How can I just serve the file and not apply a redirect in this case?
thank
source to share
Place the statement return
inside the block location
:
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, simplify your other block location
.
source to share