According to my understand of how nginx processes a request, the following nginx configuration should lead to all requests matching the prefix location /
, and thus be served an HTTP/1.1 301 Moved Permanently
response redirecting to the https version of the site.
server {
listen 80 default_server;
location / {
return 301 https://$host$request_uri;
}
return 444;
}
However, that is not what happens:
$ curl localhost
curl: (52) Empty reply from server
nginx seems to favor returning 444 (which closes the connection) above responding with the expected redirect.
Obviously this specific example is easily solved by removing the return 444
statement, but my real life config files are dynamically generated with zero or more location blocks, and I'd prefer having the final "catch-all" return 444
to prevent nginx from serving its built-in welcome page. Why doesn't this work?