Nginx服务静态中断页面但不显示图像-它们502

时间:2018-08-16 06:43:20

标签: tomcat nginx

我目前有一个Web应用程序在端口8081上运行Tomcat,并且我正在nginx监听端口8080(iptables将80路由到8080),如下所示。 我正在尝试配置要在Tomcat由于任何原因崩溃时显示的中断页面。

server {
        listen      8080;
        server_name my.url.com.au;
        port_in_redirect off;
        root    /var/www/app/;

        location / {
            proxy_pass http://my.url.com.au:8081; #not 127.0.0.1 due to Tomcat aliases
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout 150;
            proxy_send_timeout 100;
            proxy_read_timeout 100;
            proxy_buffers 4 32k;
            client_max_body_size 8m;
            client_body_buffer_size 128k;
        }

        error_page 501 502 503 /TemporaryOutage.html;
        location = /TemporaryOutage.html {
            root /etc/nginx/outage-page/;
        }
}
#there is also another server to handle https configured in a similar fashion.

当我关闭Tomcat进行测试时,我得到的TemporaryOutage.html页面显示为exepcted,但其中有两个嵌入了以下语法的图像没有显示。

src="/Logo.JPG"

正在检查ngingx访问日志,正在从我的Web应用程序访问这两个图像,并返回502错误:

xx.xx.xx.xx - site [16/Aug/2018:16:33:34 +1000] "GET /Logo.JPG HTTP/1.1" 502 2175 "https://my.url.com.au/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
xx.xx.xx.xx - site [16/Aug/2018:16:33:34 +1000] "GET /Service.png HTTP/1.1" 502 2175 "https://my.url.com.au/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
xx.xx.xx.xx - site [16/Aug/2018:16:33:34 +1000] "GET /favicon.ico HTTP/1.1" 502 2175 "https://my.url.com.au/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"

有什么方法可以使中断页面以静态方式存储这些图像,而无需在停机时直接定向到该应用?

1 个答案:

答案 0 :(得分:0)

发布问题后,我立即尝试了更多配置,并发现了可行的方法。
事实证明,我必须单独包括图像位置并根据需要提供它们。

    location = /Service.png {
        root /etc/nginx/outage-page/;
    }
    location = /Logo.JPG {
        root /etc/nginx/outage-page/;
    }
    location = /favicon.ico {
        root /etc/nginx/outage-page/;
    }