Nginx Proxy Error Page
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company nginx proxy_intercept_errors Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Nginx Error_page
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, nginx default error page just like you, helping each other. Join them; it only takes a minute: Sign up nginx not serving my error_page up vote 19 down vote favorite 3 I have a Sinatra application hosted with Unicorn, and nginx nginx error_page 404 in front of it. When the Sinatra application errors out (returns 500), I'd like to serve a static page, rather than the default "Internal Server Error". I have the following nginx configuration: server { listen 80 default; server_name *.example.com; root /home/deploy/www-frontend/current/public; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 5; proxy_read_timeout 240; proxy_pass http://127.0.0.1:4701/; } error_page 500 502 503 504 /50x.html; } The error_page directive
Nginx Custom Error Pages
is there, and I have sudo'd as www-data (Ubuntu) and verified I can cat the file, thus it's not a permission problem. With the above config file, and service nginx reload, the page I receive on error is still the same "Internal Server Error". What's my error? nginx custom-error-pages share|improve this question asked Jan 3 '12 at 16:10 Francois Beausoleil 8,94484164 add a comment| 2 Answers 2 active oldest votes up vote 41 down vote accepted error_page handles errors that are generated by nginx. By default, nginx will return whatever the proxy server returns regardless of http status code. What you're looking for is proxy_intercept_errors This directive decides if nginx will intercept responses with HTTP status codes of 400 and higher. By default all responses will be sent as-is from the proxied server. If you set this to on then nginx will intercept status codes that are explicitly handled by an error_page directive. Responses with status codes that do not match an error_page directive will be sent as-is from the proxied server. share|improve this answer answered Jan 3 '12 at 16:48 Stephen Emslie 4,26741724 1 I knew it was a question of RTFM. Thanks for taking the time to provide a great answer! –Francois Beausoleil Jan 3 '12 at 17:10 4 Just a quick note to a 4
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring nginx custom error page not working developers or posting ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ nginx proxy_intercept_errors example Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's how
Nginx Error Page Redirect
it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Catch upstream down (502) errors and display custom error page up vote 1 down vote favorite This question should http://stackoverflow.com/questions/8715064/nginx-not-serving-my-error-page have been answered a longtime ago, but I can't seem to figure it out despite reading many common answers, can someone please point out why my configuration isn't working? Goal: when upstream server_api is down (say, its worker processes has crashed), I want nginx to display my custom error page. My configuration: location @server { proxy_pass http://server_api; proxy_redirect off; ... proxy_intercept_errors on; error_page 502 /error-502.html; } error_page 502 /error-502.html; location = /error-502.html { internal; root /srv/my-server/html; } My steps: I have http://serverfault.com/questions/680470/catch-upstream-down-502-errors-and-display-custom-error-page my static error page at /srv/my-server/html/error-502.html ready, same permission and owners as other static assets. I have stopped my upstream service, and see [error] 2359#0: *25 connect() failed (111: Connection refused) while connecting to upstream appearing in logs. Now I try to make my custom error page show up for 502 errors. I have tried setting error_page at both or either server or location block. I have tried error_page with proxy_intercept_errors on in the location or server block; None of them appear to persuade nginx to display my error page. Why not? What have I missed? nginx custom-errors share|improve this question asked Apr 4 '15 at 18:33 bitinn 181110 Post the complete server block. –Michael Hampton♦ Apr 4 '15 at 20:17 @MichaelHampton Thx, I figured it out finally, please see if there are any flaws in my answer. –bitinn Apr 5 '15 at 7:22 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Thanks Justin and Michael for pointing me in the right direction, it indeed is a location block causing my troubles, in particular: location / { try_files $uri $uri/ @server; error_page 403 = @server; } Basically, I was trying to be clever and catch $uri/ error (403 happens when you try to access a folder that exists but has no index file or auto-indexing) and redirect it to @server block as well. But isn't try_files $uri
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or http://serverfault.com/questions/418539/handling-errors-in-nginx-in-a-reverse-proxy-configuration posting ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ Server Fault http://serverfault.com/questions/606602/nginx-change-error-page-based-on-proxy-pass-response is a question and answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Handling errors in nginx in a reverse proxy configuration up vote 4 down vote favorite 1 I'm using nginx as a reverse-proxy over error page my existing web server. I only want to manage a single set of custom error pages, and ideally within nginx as this is the level closest to the client. Now I'm fine with using the error_pages and proxy_intercept_errors settings. However: In the case of 400 (Bad Request) errors I need the underlying web server to be able to through some JSON body content, detailing why the request was bad. And so I need a way of disabling proxy_intercept_errors for 400 status codes nginx custom error only. I never want to show the default nginx error pages, for any status code. Now from what I can see, in order to achieve this I would need to explicitally list out every possible status code imaginable, and have an error page for it? Rather than just wildcarding all errors above 500 for example. My questions are - Are the above 2 issues resolvable within nginx itself? If not, is there an obvious solution to the issues above? nginx web-server share|improve this question asked Aug 17 '12 at 10:03 isNaN1247 9051917 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted I hadn't read the documentation correctly. In-fact the bypassing of the rules by a 400 error is a simple as not having an error page directive. This is from the proxy_intercept_errors documentation entry: If you set this to on then nginx will intercept status codes that are explicitly handled by an error_page directive. Responses with status codes that do not match an error_page directive will be sent as-is from the proxied server. (emphasis my own) share|improve this answer answered Aug 19 '12 at 8:23 isNaN1247 9051917 add a comment| Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example). Subscribed! Success! Please click the link in the confirmation email to activate your subscription. up vote 1 down vote Try the fo
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top nginx - Change error_page based on proxy_pass response up vote 0 down vote favorite Is it possible to change the fallback error_page based on the response of the upstream proxy? upstream serverA { server servera.com; } upstream serverB { server serverb.com; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for proxy_set_header Host $host; proxy_pass http://serverA; proxy_intercept_errors on; # if serverA returns 'hard' 404 # IE returns X-HARD-404=true header return 404; # else I would like to fallback to server-b error_page 403 404 500 502 504 = @serverB; } The reason I would like to do this is to an issue with our setup. Usually we send a request to server-a and if that returns a 404, we ask server-b to return the page. In this case, we do not want server-b to return its page, and we want to explicitly return a 404 without trying server-b. nginx http-headers share|improve this question edited Jun 19 '14 at 22:04 asked Jun 19 '14 at 21:57 Nathan Lee 1014 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote You could also serve the error page direct from nginx. If serverA gives a 404, send 404.html from /your/nginx/html/directory/ without involving serverB server { listen 80; location / { proxy_pass http://serverA/; proxy_intercept_errors on; proxy_redirect off; error_page 404 /404.html; } location /404.html { root /your/nginx/html/directory/; } } share|improve this answer answered Jun 20 '14 at 11:35 John