pyrocms/pyrocms — Issue #1082: Login problems with nginx and multiple domains
Author: swilla
Created: 2012-01-19 02:11:07+00:00
State: open

When using multiple domains to access a PyroCMS Community site, or using multiple domains to access PyroCMS Professional using multisite there are login problems with you do not use the primary domain in the nginx config.

The issue:

Example Nginx config:

server_name boom.domain.com boom2.domain.com;

I can login using boom.domain.com, but the page just refreshes when I try and login when I go to the site with boom2.domain.com. I have cleared my cookies and used completely separate browsers to test this and the same results occur. If I switch the order that the domains are listed in the nginx config I can login with boom2.domain.com and not boom.domain.com.

After investigating I think I stumbled upon the problem:

nginx uses the primary domain in the config as "$_SERVER['server_name']" where Apache uses the current domain for both $_SERVER['HTTP_HOST'] and $_SERVER['server_name'] regardless of the ServerName directive in the config.

Why I think this is a problem:
The cookie is created using the $_SERVER['server_name'] which needs to match the domain your are accessing the site with.

This can easily be fixed using the Community version because you can just 301-redirect all the alias' to your main domain. This way there is no discrepancy.

For Professional multisite I'm not sure what the solution is here is the scenario:

Hosting 1 domain with multiple subdomains:
Example:
delaware.domain.com
maryland.domain.com

Optional configs:
server_name delaware.domain.com maryland.domain.com;
or
server_name *.domain.com;

Both situations will never match all the sites that would be setup so you can't login to all sites. If I use the wildcard, I can't login to any of the sites.

I'm looking into seeing if there is a way to configure nginx to assign the $_SERVER['server_name'] differently.