linux,  nginx

[nginx]proxy_pass 失败时回退到 try_files

需求

访问网站时,默认显示反向代理proxy_pass的内容,如果后端服务器无法连接(一般会报502),则显示预先渲染好的本地文件。

location / {
         proxy_pass http://172.22.0.13:80;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         error_page 400 403 502 503 504 = @backend;

}

location @backend {
  try_files $uri $uri/ /index.php?$args;
}

留言

您的电子邮箱地址不会被公开。 必填项已用 * 标注