How to set up nginx proxy_pass to follow upstream 302 redirects with multiple redirects
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 38/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- nginx
- Domain
- devops
Research direction
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.
Written by the indexing model from the issue text.
Description
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;
}
}
- Dominant language
- Python
- Stars
- 5
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from davideuler/programming-tips
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
build milvus on Mac Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in davideuler/programming-tips
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100