I’m dealing with this for days and need help fellows! I hope somebody here han solve this:
3 WordPress websites (3 dedicated IP’s)
I’ve used this Ansible playbook to deploy: https://github.com/zach-adams/hgv-deploy-full
This is the fullstack:
Ubuntu 14.04 (Dedicated Server, no firewall)
- Percona DB (MySQL)
- HHVM (Default PHP Parser)
- PHP-FPM (Backup PHP Parser)
- Nginx Varnish (Running by default)
- Memcached and APC
- Clean WordPress Install (Latest Version)
- WP-CLI
All working ok. I checked headers and Varnish is working. When I try to force 301 from non-www to www with Varnish in each individual site, it enter in a url redirect loop. I added to the Nginx configuration this line as i read in some documentation:
server {
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
It doesn’t work and i think it’s for the Varnish configuration. I followed some of this documentation but nothing worked for me:
- https://www.tinywp.in/varnish-301-redirection/
- https://easyengine.io/tutorials/nginx/www-non-www-redirection/
- https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-ubuntu-14-04
I hope somebody can illuminate me 🙂
In order to redirect from non-www to www using Varnish you will neeed to do the following:
1- Disable any redirect rules that written in nginx configuration.
2- redirect non-www to www through varnish using the following snippet:
Note: I used the above snippet today and it worked correctly for me (it will work with Varnish 3 which is used in the playbook that mentioned in your question)
If you would like to redirect using nginx you can try this:
Use one method only either varnish or nginx. In case you have nginx as the front end i suggest you to go with nginx way.