Skip to content

Instantly share code, notes, and snippets.

@melo
Created May 16, 2012 17:17
Show Gist options
  • Save melo/2712335 to your computer and use it in GitHub Desktop.
Save melo/2712335 to your computer and use it in GitHub Desktop.
strange nginx behaviour with error_page + proxy_pass
I expected the first configuration below, simple.conf, to work just fine.
But it doesn't. My app server receives the second hit with the same URI as the first hit.
On the second config, wtf.conf, I keep the original URL on a variable to use in the error redirect.
My question is this: why doesn't the first simple.conf configuration works?
server {
server_name my.site;
listen 80;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_intercept_errors on;
}
error_page 404 /errors/404;
location /errors/ {
proxy_pass http://127.0.0.1:5000;
internal;
}
}
server {
server_name my.site;
listen 80;
location / {
## Keep copy of original URL
set $orig_uri $uri$is_args$args;
proxy_pass http://127.0.0.1:5000;
proxy_intercept_errors on;
}
error_page 404 /errors/404;
location /errors/ {
rewrite . /errors/404$orig_uri break;
proxy_pass http://127.0.0.1:5000;
internal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment