I have an nginx config that is similar to this:
server {
server_name my-english-site.com my-french-site.com;
listen 0.0.0.0:80;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 0.0.0.0:443 ssl;
server_name my-english-site.com my-french-site.com;
}
When someone goes to http://my-french-site.com, it redirects to https://my-english-site.com, because the rewrite directive uses the first server in the $server_name
directive.
I tried replacing $server_name
with $host
, expecting it to use the value of the Host
request header. But it still redirects to the English URL.
How can I get non-HTTPS requests redirected to the corresponding HTTPS URLs?
Thank you!