我正在使用以下方法在后端服务器关闭时提供良好的回退错误消息。
问题是浏览器将响应下载为文件,而不是显示为HTML响应。
location @fallback {
echo_status 504;
add_header Content-Type: "text/html; charset=UTF-8";
echo "<!DOCTYPE html>";
echo "<html lang='en'>";
echo " <head>";
echo " <meta charset='utf-8'>";
echo " <title>Backend is down</title>";
echo " </head>";
echo " <body>";
echo " Backend service is offline, please retry in few minutes. $echo_timer_elapsed";
echo " </body>";
echo "</html>";
}
location / {
error_page 502 504 = @fallback;
proxy_connect_timeout 10s;
proxy_pass http://backend:8090;
proxy_read_timeout 10800s;
}