NGINX - Как перенаправить на тайм-аут 504 шлюза - PullRequest
0 голосов
/ 25 апреля 2018

Я использую NGINX в качестве обратного прокси для стеклянной рыбы.Когда glassfish возвращает 50-кратные ошибки, я могу идентифицировать и перенаправить на другой ресурс из cdn.

Но если время просто истечет, NGINX ответит пользователю тайм-аутом 504 шлюза вместо перенаправления нахороший ресурс в CDN через переписывание.

Я хотел бы сделать то же самое в этом случае, если время ожидания NGINX, я хочу перенаправить на другой URL, так же, как в @ redir_404.

Как мне этого добиться?

Спасибо.

server {
listen *:80;
ssl off;

access_log  /var/log/nginx/access-.log;
error_log   /var/log/nginx/error-.log;

client_max_body_size 60m;

location @redir_404 {
    rewrite /ad/(.*?)(\?.*)?$ $scheme://cdn.company.com/ad/$1/index.html break;
    rewrite /tag(.*?)$  $scheme://cdn.company.com/tag/pixel.png break;
}

location / {
    proxy_intercept_errors on;
    set_real_ip_from 192.23.45.16;
    real_ip_recursive on;
    real_ip_header X-Forwarded-For;

    proxy_pass http://localhost:8080;

    # Force timeouts if one of the backend is dead #
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;    

    # Set headers #
    proxy_set_header    Host        $host;
    proxy_set_header    X-Real-IP   $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;
    proxy_set_header        X-Umotion-Ip    $remote_addr;
    proxy_set_header        User-Agent    $http_user_agent;

    add_header      Front-End-Https on; 

    # By default we don't want to redirect #
    proxy_redirect off;

    # Force cache-control to no-cache for /tag and /ad
    location ~ ^/(tag|ad) {
        proxy_pass http://localhost:8080;
        add_header Cache-Control "private, no-cache, no-store, must-revalidate, proxy-revalidate";
    }

    error_page 403 404 405 500 501 502 503 504 = @redir_404;
}

}

1 Ответ

0 голосов
/ 26 апреля 2018

Добавление местоположения страницы ошибок для перенаправления внутри блока вашего сервера.

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
        root /usr/share/nginx/html;
        internal;
  } 

Мы можем настроить страницы с ошибками по мере необходимости (/50x.html - страница, разработанная для Cutom)

...