David Foie Gras
David Foie Gras

Reputation: 2080

On nginx, Are those two server setting equal things?

I have settings to www rewrite or return.

1:

server {
    listen       80;
    server_name  example.com;
    return       301 https://www.example.com$request_uri;
}

2:

server {
    listen         80;
    server_name    example.com;
    return         301 https://www.$host$request_uri;
}

Are these two things equal?

It seems to be working well, but I can't have assurance.

Upvotes: 1

Views: 26

Answers (1)

Richard Smith
Richard Smith

Reputation: 49702

It depends on which server block is the default server for port 80.

If this server block is also the implicit default server for port 80, it may need to handle requests for server names other than example.com, in which case the value of $host will not be equal to the value of $server_name. See this document for more.

You could use $server_name instead of $host. See this document for details.

Upvotes: 1

Related Questions