Two domains and multiple server blocks

Reinis Rozitis r at
Sat Aug 12 12:58:20 UTC 2017

> Here, whenever I enter in my browser, I am redirected to
> I dont understand this behavior at all. All examples about
> nginx and multiple vhosts with different domains just use the appropriate
> server_name entries, so I'm really stuck here.

First - I would try to upgrade nginx / you are using quite an old (~3 years) version 1.6.2.  

I don't particularly remember at what point but there have been some issues/changes on how nginx handles virtual server priority. At least I've seen a similar issue in serving wrong SSL certificates (as in chosing the wrong virtual server block / SNI not working as expected) which went away after upgrade to a most recent version.

While it may not be the case here it's a good point to start for a better support.

Looking at the response headers for

Connecting to (||:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 301 Moved Permanently
  Server: nginx/1.6.2
  Date: Sat, 12 Aug 2017 12:48:45 GMT
  Content-Type: text/html; charset=UTF-8
  Connection: keep-alive
  Set-Cookie: wsc30_cookieHash=3fffeb677df909960a434c5f05d66f2007cde491; path=/;; HttpOnly

There is a cookie for .. which means that the request is actually passed to php (also the redirect could come from php not nginx) which shouldn’t happen with:
    return 301$request_uri;

what again indicates that the request is handled by the first server {} block rather than the one you expect.


More information about the nginx mailing list