我一直在将 Nginx 设置为服务器上应用程序的反向代理。其中一部分包括具有外部内容(如图像)的维护页面。我找到了一种设置图像返回 200 的错误页面的方法,但看起来反向代理会改变整个环境。这是来自的原始解决方案nginx 维护页面有内容问题 https://stackoverflow.com/questions/5984270/nginx-maintenance-page-with-content-issue
error_page 503 @maintenance;
location @maintenance {
root /path_to_static_root;
if (!-f $request_filename) {
rewrite ^(.*)$ /rest_of_path/maintenance.html break;
}
return 200;
}
反向代理配置为:
location / {
proxy_pass http://127.0.0.1:9007/;
proxy_redirect off;
}
问题问题是,当发现“维护”根目录中存在文件时,就会出现问题,服务器返回 502。有人知道原因可能是什么吗?
一些猜测我想知道服务器是否侦听端口 80,它会以某种方式将任何好的文件请求传递回代理。如果这是真的,如何避免这种情况?
Edit
这是 nginx 日志中的错误。我直接尝试访问 50x.html。不确定为什么会发生这种情况?
2012/02/17 19:39:15 [error] 21394#0: *13 connect() failed (111: Connection refused) while connecting to upstream, client: (my ip address), server: _, request: "GET /50x.html HTTP/1.1", upstream: "http://127.0.0.1:9007/50x.html", host: "domain.com"
看起来确实是这样indeed尝试从应用程序而不是根获取。我怎样才能绕过这个?
Edit 2
我原本以为我已经找到了对 nginx v1.0.12 进行更改的答案,但它并没有解决问题。它涉及类似的情况,但我的猜测是修复过于具体。