使用https和虚拟主机为nginx设置自定义错误页
从服务器故障交叉过帐 我们有一个nginxopenresty1.4.2.7实例作为负载平衡器。它有两个服务器指令,一个用于服务一个特定的站点,我们称之为www.our-special-host.com,另一个用于其他所有站点的通配符。我们正在尝试对其进行配置,以便根据两个服务器指令的后端中的哪一个关闭,显示不同的502错误页面 我们的配置适用于HTTP,但不适用于HTTPS。如果我们关闭后端并点击www.our-special-host.com,我们会得到HTTP和HTTPS的相应错误。但是,如果我们访问任何其他托管站点,我们将获得HTTP的正确错误页面,但对于HTTPS,我们将获得www.our-special-host.com的错误页面 以下是我们轻松编辑的配置:使用https和虚拟主机为nginx设置自定义错误页,nginx,virtualhost,reverse-proxy,custom-errors,proxypass,Nginx,Virtualhost,Reverse Proxy,Custom Errors,Proxypass,从服务器故障交叉过帐 我们有一个nginxopenresty1.4.2.7实例作为负载平衡器。它有两个服务器指令,一个用于服务一个特定的站点,我们称之为www.our-special-host.com,另一个用于其他所有站点的通配符。我们正在尝试对其进行配置,以便根据两个服务器指令的后端中的哪一个关闭,显示不同的502错误页面 我们的配置适用于HTTP,但不适用于HTTPS。如果我们关闭后端并点击www.our-special-host.com,我们会得到HTTP和HTTPS的相应错误。但是,如
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;
}
所有相关主机均为XXX.ourdomain.com,证书为*.ourdomain.com
我们还尝试向第二个服务器块添加一个显式的catch-all正则表达式,即
server_name ~^.*$;
这种行为仍然是错误的,但不同的是错误的:
带有http的特殊站点:我们得到了错误的错误页面,loadbalancer\u 502\u on\u other\u hosts.html
使用https的特殊站点:我们在\u Special\u host.html上获得了正确的错误页面loadbalancer\u 502\u
使用http的非特殊站点:我们得到了正确的错误页面,loadbalancer\u 502\u on_other\u hosts.html
使用https的非特殊站点:我们得到了正确的错误页面,loadbalancer\u 502\u on_other\u hosts.html