I believe you need to put the `return 301 ...` inside a location block too. Otherwise, it overrides all the location blocks.
I'm on my phone now, but I'll try to share a sample file from one of my servers (that works as you want it) when I get back to my computer. Moshe On Sun, Dec 2, 2018, 5:03 PM Mik J via nginx <nginx@nginx.org wrote: > Hello, > > I'd like to be able to offer let's encrypt in port 80 only and redirect > everything else to port 443 > > server { > listen 80; > listen [::]:80; > listen 443; > listen [::]:443; > server_name http://www.mydomain.org blog.mydomain.org; > location ^~ /.well-known/acme-challenge { default_type > "text/plain"; root /var/www/letsencrypt; } > location = /.well-known/acme-challenge/ { return 404; } > return 301 https:// mydomain.org; > } > > My problem is that everything is redirected and I cannot access a file in > /var/www/letsencrypt/.well-known/acme-challenge > When I comment the return 301 it works but I loose the redirection. > > It seems to me that nginx parses everything where I would expect it to > stop at > location ^~ /.well-known/acme-challenge { default_type "text/plain"; root > /var/www/letsencrypt; } > > Does anyone know the trick ? > _______________________________________________ > nginx mailing list > nginx@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx