How to set up nginx proxy_pass to follow upstream 302 redirects with multiple redirects

Aperta
#25 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
38/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
nginx
Ambito
devops

Direzione di ricerca

Start with the nginx configuration in the issue, especially proxy_set_header, proxy_intercept_errors, recursive_error_pages, error_page, and the @handle_redirect location. Check the repository's existing tip format and placement before documenting this example. Done means the setup is recorded clearly with the multi-redirect behavior and required directives explained.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The following config shows how to set up nginx proxy to follow upstream 302 redirects.
The upstream server only receive hostname as api.upstream.com, so proxy_set_header directive is necessary.
And the upstream has upstreams recursively, so need to enable recursive_error_pages.

Then the client would get normal 200 response instead of 302 from nginx.


server {
    listen               80 myserver.com;

     # redirect health status page without Host header:
     location /health.status {
       proxy_pass   http://api.upstream.com;
       proxy_redirect http://api.upstream.com/ /;
       proxy_intercept_errors on;
       recursive_error_pages on;
      error_page 301 302 307 = @handle_redirect;
    }


    location / {
        #proxy_pass   http://127.0.0.1:8080;
        proxy_pass   http://api.upstream.com;

        ## set Host to target server host name
        proxy_set_header Host "api.upstream.com";
        proxy_redirect http://api.upstream.com/ /;

        proxy_intercept_errors on;
        recursive_error_pages on;
        error_page 301 302 307 = @handle_redirect;

    }

   location @handle_redirect {
       set $original_uri $uri;
       set $orig_loc $upstream_http_location;

       # nginx goes to fetch the value from the upstream Location header
       proxy_pass $orig_loc;
   }
}
Lingua principale
Python
Stelle
5
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di davideuler/programming-tips

Tutte le issue di davideuler/programming-tips

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.