I am having issues with trying to get a WordPress Multisite (using subdomains) running on nginx.
Here is my ideal set-up:
domain.com
sub1.domain.com
sub2.domain.com
sub3.domain.com
Any requests to www.domain.com
should be 301'd to domain.com
(my understanding is that WordPress strips out www anyways?)
I am not wanting to access any of the subdomains by any other means, e.g domain2.com
would direct a user to sub2.domain.com
- this isn't what I want.
I have followed this DigitalOcean tutorial and everything has worked fine with regular WordPress installs.
My local hosts file is set up as follows:
XXX.XXX.XXX.XXX domain.com
XXX.XXX.XXX.XXX sub1.domain.com
etc...
My issue is that whenever I attempt to visit either domain.com
or sub*.domain.com
, I am redirected to a completely different site on my server, the one which just so happens to be the top of the list in sites-enabled
. On closer inspect, when checking the Network tab in Chrome, I can see that my request for domain.com
or sub*.domain.com
is 301 redirected to the aforementioned unrelated site.
I have flushed my local Chrome cache, am constantly using Incognito mode and I just cannot shake this redirect. I'm even using Firefox as I rarely use it so wouldn't expect any caching whatsoever for domain.com
I may be completely off the mark here and it could be nothing to do with the browser at all but rather the server and nginx configuration. Something is forcing a 301 and I don't know what.
It seems that this plugin comes up a lot in discussion but as far as I can tell, this is only applicable when wanting to map a regular domain to a subdomain, which isn't what I want.
Can anyone please offer any advice/solutions as to how I can configure so everything is routed correctly? My local environment runs a LAMP stack so I have had this working and I have altered the wp-config.php
file to reflect the new 'live' domain (remember, I have not configured DNS, I have just hacked around in etc/hosts
.
Any help much appreciated as always :)
So in the end I decided to build the multisite from scratch in my nginx environment as opposed to trying to take what worked in Apache and re-configure for nginx. As far as I can tell, I had updated everything that you would expect to have to do so from Apache to nginx as well as updating local domains to live ones in the database and wp-config.
While this approach didn't strictly 'fix' my issue, I do feel like I've learned a valuable lesson here - sometimes starting from scratch is better than trying to make something fit!