The site opens over HTTPS, but the old http:// address still serves the page.
curl -I prints only the response headers: 200 OK means the page went over the network as plain text. The server block on port 80 still serves it as before.
Such a server block is kept for redirecting: to any request it answers with status code 301 and a Location header saying where to go. A browser and curl -L repeat the request at the new address on their own.
return answers the client right away without looking for files in root. $host is the site name from the request, $request_uri is the path together with the parameters after ?. That way http://app.lab.test/cart?id=7 goes exactly to https://app.lab.test/cart?id=7.
The server block on 80 says return 301 https://$host;. Where will nginx send a request for http://app.lab.test/cart?id=7?
-
returnanswers right away without looking for files in root: code 301 andLocation: https://app.lab.test. -
The path with its parameters comes from
$request_uri, which is not in the line.curl -IshowsLocation: https://app.lab.test. -
return 301sends the client to the address written after the code, and it starts with https://.
$host fills in only the site name; the path and parameters come from $request_uri. Without it every old address lands on the home page, and links to the site's pages break.
Key points
-
A server block on 80 with
return 301 https://$host$request_uri;sends any request to HTTPS with the same path. -
The 301 code and the
Locationheader show up incurl -I, andcurl -Lfollows them on its own.