4

I have a server block to redirect all http requests to https as follows:

server {
   listen 0.0.0.0:80;
   listen [::]:80;
   server_name a.com b.com c.com;
   return 301 https://$server_name$request_uri;
}

It seems that requests coming in using all three domain names on port 80 will be redirected to https://a.com. Is this how $server_name is set?

Old Geezer
  • 397
  • 8
  • 25
  • 4
    You probably want to use `$host` instead of `$server_name`. See [What is the difference between Nginx variables $host, $http_host, and $server_name?](https://serverfault.com/q/706438/126632) – Michael Hampton Aug 01 '18 at 15:05

1 Answers1

2

http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name

The first name becomes the primary server name.

You can use three separate server blocks, or Michael Hampton's excellent suggestion of the $host variable instead.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106