0

I am trying to use error_page like the following, to trap errors, and then read content from an external url, and send that to the client:

    error_page 404    =404      @err404;                                                                                                                                                               
    location @err404 {                                                                                                                                                                                  
             proxy_pass     http://www.myserver.com;                                                                                                                                                     
    }

This is in the "server" directive. I want any 404 to be caught by this (it is) - and then the content from http://www.myserver.com read - and returned as the body of the 404 returned to the client.

This almost works - but when I try to access http://myserver/somenonexistingURL, proxies through to http://www.myserver.com/somenonexistingURL - which seems unhelpful - is there a way to have it just proxy the content of exactly what I typed? Not proxy the entire request?

If I put

error_page 404 http://backend

Then I get a 30X redirect (as per the docs) - which is not what I want either.

Any ideas?

Docs: http://wiki.nginx.org/HttpCoreModule#error_page and http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page

1 Answer 1

1

Here is what worked for me:

error_page 404    =404      @err404;                                                                                                                                                                
      location @err404 {
           rewrite ^/(.*) /       break; 
           proxy_pass     http://www.unsw.edu.au;                                                                                                                                                          
      }

This both returns 404 as the http status code, and the contents from the proxy_pass url - but without any path appended.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .