Situation
I'm trying to host 2 Wordpress websites on the same virtual machine.
- Site1: www.mainsite.com
- Site2: site2.mainsite.com
Each site has its own Wordpress installation and database (not multisite).
Environment
- Ubuntu 18.04
- Nginx 1.17.1
- PHP7.3-FPM
- Certbot for Let's Encrypt
- HSTS activated for domain
Problem
After installing both Wordpress websites and logging in on wp-admin. The last one starts redirecting to the other one with a 301 redirect.
Steps to reproduce:
- Clear browser cache
- Visit www.mainsite.com/wp-admin and login
- Visit site2.mainsite.com/wp-admin and login
- Visit www.mainsite.com
- Visit site2.mainsite.com -> Gets redirected to www.mainsite.com with X-Redirect-By: WordPress in the response header
This is not always true, sometimes it works for a few minutes before it starts to redirect. The 301 redirects get cached by the browser, so when the redirect occurs, it never works again unless I manually clear my browser cache.
Tried solutions
- Clearing browser cache, tried another computer
- Added WP_HOME and WP_SITEURL to both wp-config.php files
- Checked my Nginx server blocks and PHP-pools
- Tried separate SSL certificates with Certbot
- Tried wildcard SSL certificate with Certbot
- Reboot
- Checked both MySQL databases for URLS
Do I have to add something in the Wordpress config to stop the redirect? I think it has something to do with the cookie that got created when logging in.