I just rebuilt the VPS again and got it working. Thanks a million for helping me troubleshoot this!
I was actually keeping them in separate server blocks, but I was making two rookie mistakes:
First, I had not removed example.com
from the server_name
line in the first block, so the second server block for example.com
was completely ignored. Funny thing is, I actually thought of this, but I guess I missed the memo that said Nginx is not CSS where the last declaration wins 😀
And when I realized my folly and fixed this, I also had return 301 https://www.$host$request_uri;
in /etc/nginx/conf.d/force-ssl-example.conf --- and this was creating a redirect loop for www.example.com. I had to change the $host
variable to the actual domain (ie return 301 https://www.example.com$request_uri;
) to stop this redirect loop.
So now all roads lead to www.example.com
, and I'm good to go.
Thank you again!