Rafa_F
April 4, 2016, 9:38pm
1
Hello,
I am struggling to understand the error_page directive behavior:
server {
listen 80;
listen [::]:80;
server_name example.org ;
location /proxied {
return 418 "Host: $host, Connection: $http_connection";
}
}
server {
listen 80;
listen [::]:80;
server_name example.com ;
root /var/ious/files;
error_page 418 = /error_page.html;
proxy_intercept_errors on;
location /proxy {
proxy_pass http://example.org/proxied;
}
}
Expected behavior:
->Request to http://example.com/proxy
→ Sub-request to http://example.org/proxied
→ Response HTTP 418
→ Error page for HTTP 418 served http://example.com/error_page.html
Observed behavior:
→ Request to http://example.com/proxy
→ Sub-request to http://example.org/proxied
→ Response HTTP 418
→ Error page HTTP 404 (???)
The error_page.html file exists in the example.com root directory as
any
other file.
No error message in the error_log file (warn level).
I am running nginx v1.8.1.
What am I doing/understanding wrong?
B. R.
B.R
April 4, 2016, 9:54pm
2
On Mon, Apr 04, 2016 at 09:36:36PM +0200, B.R. wrote:
Hi there,
I am struggling to understand the error_page directive behavior:
I do not get the full same results that you report, when I use 1.9.2.
Expected behavior:
->Request to http://example.com/proxy
→ Sub-request to http://example.org/proxied
→ Response HTTP 418
→ Error page for HTTP 418 served http://example.com/error_page.html
No. Your “error_page” with “=” eats the 418 status.
Observed behavior:
→ Request to http://example.com/proxy
→ Sub-request to http://example.org/proxied
→ Response HTTP 418
I do get that much.
→ Error page HTTP 404 (???)
I only get 404 if error_page.html does not exist. If it does exist,
I get it with http 200.
Aside from that: I suspect that proxy_intercept_errors does exactly the
opposite of what you think it does.
What happens if you set it “off”?
What am I doing/understanding wrong?
error_page normally does not change the http status. Your extra config
told it to change it.
Cheers,
f
Francis D. [email protected]
B.R
April 4, 2016, 10:13pm
3
On Mon, Apr 04, 2016 at 08:54:12PM +0100, Francis D. wrote:
On Mon, Apr 04, 2016 at 09:36:36PM +0200, B.R. wrote:
Hi there,
-> Error page HTTP 404 (???)
I only get 404 if error_page.html does not exist. If it does exist,
I get it with http 200.
Aside from that: I suspect that proxy_intercept_errors does exactly the
opposite of what you think it does.
Apologies - I was wrong there.
“proxy_intercept_errors on;” means that error_page is used for the
returned http status.
“proxy_intercept_errors off;” means that it is not, and the full
original
status+body gets to the client.
So you had (and have) it the way that you want it to be.
f
Francis D. [email protected]
B.R
April 4, 2016, 10:51pm
4
Whoops!
Minimal test configuration FTW… There was a ‘/’ prefix location block
hidden at the bottow of my server one, with an ugly ‘try_files $uri.php
=404;’ directive…
As notes, though :
I removed the ‘=’ parameter from the error_page directive to simplify,
as
there is no special processing during error handling.
I forgot to update the configuration snippet in the mail.
Let’s be clear about proxy_intercept_errors:
Setting it to ‘on’ enables error processing through error_page.
The default (off) simply propagates the proxy error (status code >= 300)
to
clients.
I should have double/triple/quadruplechecked the configuration before
writing on this ML.
Thanks for your time Francis! And sorry about that…
B. R.