Troubleshooting & How-Tos 📡 🔍 Servers

Why is NginX serving different localhost sites to Chromium vs. Safari or Firefox?

I ran into a weird problem testing some websites on a local NginX installation on my Mac, where it was sending different sites to Firefox and Chrome for the same URL.

I’d put the server names into /etc/hosts pointing to 127.0.0.1, and I’d set up NginX with multiple server {} blocks, each with a different server_name. But while Chrome would load the individual sites for one.example.com and two.example.com, Firefox would always get the content from one.example.com.

A little more testing confirmed that all Chromium-based web browsers (I tried Edge, Opera, Brave and Vivaldi) were getting the correct sites, but Firefox and Safari were both getting the wrong server’s content.

When I compared the server blocks, I noticed that one.example.com was listening on both IPv4 and IPv6, but two.example.com was listening only on IPv4. I added the second listen directive, reloaded nginx, and voila! It worked in Firefox and Safari!

    listen 443 ssl;
    listen [::]:443 ssl;
    server_name  two.example.com;

So apparently, even though I’d only pointed two.example.com to 127.0.0.7 (IPv4), Firefox and Safari were connecting to ::1 (IPv6) instead. And since NginX had only connected one.example.com to that interface, that’s the site it loaded. It’s not clear whether Firefox and Safari are both doing something weird and Chrome isn’t, or they’re both using a MacOS system resolver and Chromium is doing its own thing.

TL;DR: If you listen to IPV6 in one localhost server {} block, listen to it in all of them!