当所有服务器块都不可用时,Nginx重定向到特定服务器块

问题描述 投票:0回答:1

我有一个x.conf Nginx文件,如下:

server {
  listen 80;
  server_name example.com;

location / {
  proxy_pass http://localhost:5000;
  include /etc/nginx/conf.d/proxy-pass-set-headers;
  }
}

我需要将用户的请求自动重定向到固定的JSON文件,当由于维护或其他问题而无法使用所有URL时,该文件位于另一个服务器块中。我该怎么办?

nginx nginx-config
1个回答
0
投票
server {
 listen 80;
 server_name example.com;

 error_page  500 501 502 503 504 =200 @error;

 location @error {
   root       /opt/devops/nginx/error/;
   try_files /error.json /;
   break;
   }

 location / {
   proxy_pass http://localhost:5000;
   include /etc/nginx/conf.d/proxy-pass-set-headers;
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.