SSL Error on One Hostname Only — the Certificate Is Valid, the Firewall Sends 443 to the Wrong Server
A field story about a certificate that was valid, installed and still “broken” — the NAT rule almost nobody checks — and the two-sided test I now run before anyone reissues anything.
The ticket was one line. One internal application, published on its own hostname, was showing an SSL error in the browser.
“The certificate is new. It’s installed. The browser still says it’s wrong.”
They were right about the first two parts. I looked at the web server. Nginx was listening on 80 and 443. The certificate file was there, the name on it matched the hostname, and it had many months left to run.
So I asked one question.
“When you open that hostname from outside, whose certificate do you get?”
Silence. Everybody had read the word “error”. Nobody had read the name on the certificate.
I asked the server for its certificate from the server itself. It gave the right one.
I asked the public IP for the same hostname from the internet. It gave a certificate for a different system: another internal application, on another machine, with its own perfectly good certificate.
That’s the trap. A wrong SSL certificate does not always mean a wrong certificate. Sometimes it means a wrong server.
What Was Actually Happening — One Public IP, One Port 443
The DNS record was correct. It pointed to the customer’s public IP. But the web server does not own that public IP. The edge firewall does, and it decides which internal machine receives each port.
That decision is a destination NAT rule: “when traffic arrives on this public IP and this port, send it to that private IP and that port.” Depending on the vendor it is called a port forward, a virtual IP, a VIP or a DNAT rule. The idea is the same.
This is what everybody believed was happening:
Browser → public IP:443 → firewall → application server:443
This is what was really happening:
Browser → public IP:443 → firewall → a different internal server:443
Here’s the part that trips people up. A plain NAT rule does not read hostnames. It sees an IP address and a port. Two hostnames can point to the same public IP in DNS, but a simple port forward sends both of them to the same machine.
The browser does send the hostname early, inside the TLS handshake, in a field called SNI (Server Name Indication). A web server or a reverse proxy can read SNI and choose the right site. A plain port forward never looks at it.
So the other server received a request for a name it did not know. It did what web servers do. It answered with the certificate it had.
Where this pattern can appear:
- A second application is published behind a public IP that already has port 443 in use.
- A server is replaced or moved, and the NAT rule still points to the old private IP.
- The DNS team, the server team and the firewall team are three different teams, and each one has checked its own part.
Why the Usual Checks Miss It
Every check on the server says the server is fine. That is because the server is fine.
nginx -tpasses.- The certificate file has the right name and a valid date.
- A local request gets the right certificate.
- Staff inside the office may see no error at all, if internal DNS sends them straight to the private IP.
And the DNS check passes too, because the hostname really does point to the right public IP.
The error message does not help either. The browser says the certificate name does not match. Most people read that as “the certificate is wrong”, so they reissue it, install it again and restart the web server. Nothing changes, because visitors were never reaching that web server.
There is a similar fault that really is on the server: the hostname has no matching server block, so nginx answers with its default site’s certificate. The test below separates the two in under a minute.
How to Actually Fix This
Step 1: Ask the Server Itself (Read-Only)
Log in to the application server and ask it for its own certificate. Replace app.example.com with your hostname.
openssl s_client -connect 127.0.0.1:443 -servername app.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -enddate -fingerprint -sha256
The -servername part matters. It sends the hostname as SNI, the same way a browser does. Without it you may get the default site and chase the wrong problem.
You want to see your hostname’s certificate and an end date in the future. Keep the fingerprint.
If the wrong certificate shows up here, stop. Your problem is the web server configuration, not the firewall.
Then repeat the test with the server’s private IP in place of 127.0.0.1. The firewall will connect to that address, not to localhost.
Step 2: Ask the Public IP From Outside (Read-Only)
Now run the same question from a machine that is not on the customer’s network. A phone hotspot is enough.
First, see where the name really points:
dig +short app.example.com
Then ask that name for its certificate:
openssl s_client -connect app.example.com:443 -servername app.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -enddate -fingerprint -sha256
Compare the two fingerprints.
- Same fingerprint: visitors get the certificate you installed. Look at the chain, the dates or the client instead.
- Different fingerprint: something else is answering on that public IP.
In this case the outside answer had another hostname in the subject and a different issuer. It was not an old copy of our certificate. It belonged to a different system.
Plain takeaway: same question, two places, two answers. The fault is between them.
One warning about addresses. Take the public IP from DNS, not from a message or an old document. During this case I was also given an IP that turned out not to belong to the customer at all. The certificate it served told me so before I tried to log in to anything.
Step 3: Prove the Traffic Never Arrives (Read-Only)
This is the evidence that ends the argument between teams. On the application server, watch for new connections on 443:
sudo tcpdump -ni any 'tcp dst port 443 and tcp[tcpflags] & tcp-syn != 0'
Open the hostname from the outside machine. If the browser shows a certificate and tcpdump shows no connection from outside, the request went to another machine.
If there is a CDN or a proxy in front, that may be the thing answering. Check it first, because then the public certificate is supposed to be different from the one on your server.
Step 4: Choose the Fix — Do Not Just Move the Rule
The obvious fix is to point public 443 at the application server. Do not do that blindly. The other system is live on that port. Move the rule and you repair one hostname by breaking another.
There are three clean options:
- A second public IP. One IP per published server, each with its own 443. Simple to understand, and users type a normal address.
- A reverse proxy that reads the hostname. One public IP, one port 443, and a proxy behind it that sends each name to the right server.
- A different public port. The firewall keeps 443 for the first system and forwards another public port to the application server’s 443.
In this case the firewall was a shared one, so loading customer certificates on it and routing by hostname there was not an option. The firewall team used option 3:
Browser → public IP:8443 → firewall → application server:443
(8443 is my example port here.) The certificate did not change. A certificate is issued for a name, not for a port, so the same file is valid on 443, 8443 or any other port.
Option 3 has a price. Users must type the port in the address. Some office and guest networks block unusual outbound ports. For a small known group of users, that can be acceptable. For a public website, use option 1 or 2.
If you choose option 2, nginx can route by SNI without decrypting anything. This sits at the top level of nginx.conf, next to the http block and not inside it, and needs the stream and ssl_preread modules:
stream {
map $ssl_preread_server_name $backend {
app.example.com 10.0.0.20:443;
default 10.0.0.10:443;
}
server {
listen 443;
ssl_preread on;
proxy_pass $backend;
}
}
Each server keeps its own certificate. Two things to know before you use it: nothing else on the proxy machine can already be listening on 443, and the servers behind it will see the proxy’s IP as the client unless you also set up PROXY protocol.
I did not deploy this one in this case. It is the pattern to plan for when a second public IP is not available.
Step 5: Verify — Where Most Tutorials Stop and Where Mine Starts
A firewall rule that is “done” is not proof. Go back outside and ask again, on the new path:
openssl s_client -connect app.example.com:8443 -servername app.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -enddate -fingerprint -sha256
The fingerprint must now match the one from Step 1.
Next, check that a normal client trusts it and the application answers:
curl -sS -o /dev/null -w '%{http_code} %{ssl_verify_result}\n' https://app.example.com:8443/
200 0 is what you want: the page loaded, and certificate verification returned no error. An application that redirects to a login page may return 302 0, which is also fine. Do not add -k. That flag switches off the exact check you are trying to make.
If curl says no alternative certificate subject name matches target host name, you are still reaching the wrong server. This error is not a bug. It is the verification.
In our case the outside test showed the right certificate, a good chain and HTTP 200. That is when I called it fixed.
Last, open the other hostname too. The system that was already on 443 must still work.
The Renewal Trap Waiting Behind This
There is a second problem hiding in the same NAT table, and it appears months later.
If you use Let’s Encrypt with the HTTP-01 challenge, the validation request always starts on port 80 of your hostname. If public port 80 also goes to the other server, the challenge lands on the wrong machine and the renewal fails. Publishing the application on 8443 does not change that.
The clean answer is the DNS-01 challenge, which proves control with a DNS record and needs no inbound port. With a purchased certificate, inbound ports matter only if you validate over HTTP, but somebody has to own the renewal date.
Look at What Else the Server Is Listening On
While I was on that server, I also looked at its listening ports. A database port and a remote desktop port were both open on all interfaces, not just on localhost.
That matters here for one reason. When people are tired of port-forward problems, someone suggests a one-to-one NAT: “just map the whole public IP to the server.” If the firewall policy on top of it is loose, every one of those listening services is now on the internet.
Check before you change the NAT:
sudo ss -lntp
Anything on 0.0.0.0 or [::] is listening on every interface. Publish one port, not one server.
The Checklist I Run Before Anyone Reissues a Certificate
- Read the name on the certificate the browser gets. Not the error, the name.
- DNS points where you think.
dig +short app.example.com - The server serves the right certificate locally.
openssl s_clientto127.0.0.1:443with-servername - The public side serves the same one. The same command from outside, then compare fingerprints
- The request really arrives.
tcpdumpon the server while you test from outside - Port 80 goes to the right place too, if renewal depends on it.
curl -sI http://app.example.com/ - Only the needed port is published.
sudo ss -lntpon the server, then read the NAT rule
What I Tell Every Customer Now
When someone tells me a certificate is broken, I ask one question before we touch it:
“Which internal server does your firewall send port 443 to, and who checked that from outside?”
If the answer is a private IP and a name, they’re in good shape, and we can look at the certificate. If the answer is “it should be going to the right one”, we’re not done yet. We test from outside first.
I write about the questions I ask in real customer rooms — the ones that change architectures and surface the problems no one else noticed. If you found this useful, drop your email below and I’ll send the next one when it’s ready.
FAQs
Why does my website show another site’s SSL certificate?
Either the web server has no matching site for your hostname and answers with its default certificate, or the request is reaching a different server. Run openssl s_client with -servername on the server itself and again from outside. If the local answer is right and the outside answer is wrong, check the firewall NAT rule or any proxy in front.
Can two servers share one public IP on port 443?
Not with a plain port forward, because it sees only the IP and port and sends everything to one machine. You need a reverse proxy or load balancer that reads the hostname and routes each name to the right server. Otherwise use a second public IP or a different public port.
Do I need a new certificate if I publish the site on a different port?
No. A certificate is issued for a hostname, not for a port. The same certificate is valid on 443, 8443 or any other port, as long as users open the same hostname.
Why does the site work inside the office but show an SSL error outside?
Internal DNS often points the hostname straight to the server’s private IP, so office users never pass through the NAT rule. Outside users go to the public IP, where the firewall decides which server answers. Always test from an outside network, such as a phone hotspot.
Will reissuing the certificate fix a certificate name mismatch?
Only if the certificate on the correct server has the wrong name. If visitors are reaching a different server, a new certificate changes nothing. Compare the SHA-256 fingerprint from the server with the one seen from outside before you reissue.