如何正确使用nginx的回声支持来响应504内联页面?

我试图通过使用nginx回声支持回复一个自定义的504页面,但由于一些奇怪的原因,当这是活跃的浏览器下载响应,而不是打开它。

server { listen 80; proxy_intercept_errors on; server_name localhost; location @fallback { add_header Content-Type "text/html; charset=UTF-8"; add_header Content-Disposition 'inline; filename="504.html"'; # when this line is enabled I get the download behavior! # when this is not active, I get a 200 response, which is not desired echo_status 504; 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://google.com:1234; } } 

嘿,我今天正在testing回声模块与自定义“403”类似的configuration…

我没有正确地阅读文档,谷歌search导致我是你的问题。

Se: http : //wiki.nginx.org/HttpEchoModule#Content_Handler_Directives

而不是使用add_header Content-Type试试:

default_type“text / html; charset = UTF-8”;

我不确定add_header是否应该工作,但在模块手册中没有提到。 [编辑]:default_type很可能已经在nginx全局conf中设置为:default_type application / octet-stream; 我忘记了,所以如果你想在浏览器中看到一个响应,它仍然是最好的改变。[/编辑]

*注意:你仍然应该保留“echo_status 504” 如果你不想看到“200”的回应。