We have an nginx (OpenResty 1.4.2.7) instance acting as a load balancer. It has two server directives, one to serve one specific site (let's call it www.our-special-host.com) and one wildcard for everything else. We're trying to configure it so that different 502 error pages are shown depending on which of the two server directives' backend is down.
Our configuration works for HTTP but not for HTTPS. If we shut down the backends and hit www.our-special-host.com, we get the appropriate error both for HTTP and for HTTPS. However, if we hit any other hosted site, we get the correct error page for HTTP but for HTTPS we get the error page for www.our-special-host.com.
Here's the config we have (lightly edited):
server {
server_name www.our-special-host.com
listen 80;
listen 443 ssl;
error_page 502 /nginx_errors/loadbalancer_502_on_special_host.html;
location /nginx_errors/ {
alias /path/to/nginx_errors/;
}
location / {
proxy_pass x.x.x.x;
...
}
ssl_certificate certificate.crt;
ssl_certificate_key pk.key;
}
server {
listen 80;
listen 443 ssl;
error_page 502 /nginx_errors/loadbalancer_502_on_other_hosts.html;
location /nginx_errors/ {
alias /path/to/nginx_errors/;
}
location / {
proxy_pass y.y.y.y;
...
}
ssl_certificate certificate.crt;
ssl_certificate_key pk.key;
}
(All of the hosts concerned are XXX.ourdomain.com, and the cert is for *.ourdomain.com.)
[UPDATE] After Michael Hampton's comment below, I added an explicit catch-all regex to the second server block, ie.
server_name ~^.*$;
The behaviour is still wrong, but different:
- "Special" site with http: we get the wrong error page, loadbalancer_502_on_other_hosts.html
- "Special" site with https: we get the right error page, loadbalancer_502_on_special_host.html
- "Non-special" site with http: we get the right error page, loadbalancer_502_on_other_hosts.html
- "Non-special" site with https: we get the right error page, loadbalancer_502_on_other_hosts.html