# Cannot GET error handler - Controling HTTP\_status\_codes

**URL:** https://discourse.nodered.org/t/cannot-get-error-handler-controling-http-status-codes/59627
**Category:** General
**Tags:** http-request, nginx
**Created:** [10 March 2022 03:30 UTC](https://discourse.nodered.org/t/cannot-get-error-handler-controling-http-status-codes/59627 "2022-03-10T03:30:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)
#### Post date: [10 March 2022 03:30 UTC](https://discourse.nodered.org/t/cannot-get-error-handler-controling-http-status-codes/59627/1 "2022-03-10T03:30:16Z")

</div>

This is in response to closed thread:

> [@Cannot GET error handler](https://discourse.nodered.org/t/cannot-get-error-handler/53106):
>
> I want to customize my error handler (Cannot GET / error 404). How can i do this?

I just had to deal with this issue and found [nginx](https://www.nginx.com/) was a great solution.

Solution:

```auto
proxy_intercept_errors on;

```

[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_intercept\_errors](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors)

" Determines whether proxied responses with codes greater than or equal to 300 should be passed to a client or be intercepted and redirected to nginx for processing with the [error\_page](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page) directive."

Now nginx handles my errors instead of node-red.

How I use it in nginx

```auto
###nginx default file
server {
    	listen 80;
	    listen [::]:80;

        location = /robots.txt {
    	add_header Content-Type text/plain;
    	return 200 "User-agent: *\nDisallow: /\n";
        }

        location /static {
            alias /home/nfs/.nfs/httpStatic;
            autoindex on;
        }

        root /home/nfs/.nginx/errorpages;
        
        #400 Bad Request
        error_page 400 /400.html;
        location /400.html {}
        
        #403 Forbidden
        error_page 403 /403.html;
        location /403.html {}        

        #404 Not Found
        error_page 404 /404.html;
        location /404.html {}
        
        #405 Method Not Allowed
        error_page 405 /405.html;
        location /405.html {}

        #406 Not Acceptable
        error_page 406 /406.html;
        location /406.html {}
        
        #408 Request Timeout
        error_page 408 /408.html;
        location /408.html {}        

        #409 Conflict
        error_page 409 /409.html;
        location /409.html {}
        
        #413 Payload Too Large
        error_page 413 /413.html;
        location /413.html {}

        #414 URI Too Long
        error_page 414 /414.html;
        location /414.html {}
        
        #415 Unsupported Media Type
        error_page 415 /415.html;
        location /415.html {}        

        #417 Expectation Failed
        error_page 417 /417.html;
        location /417.html {}
        
        #423 Locked
        error_page 423 /423.html;
        location /423.html {}

        #429 Too Many Requests
        error_page 429 /429.html;
        location /429.html {}
        
        #431 Request Header Fields Too Large
        error_page 431 /431.html;
        location /431.html {}

        #444 No Response
        error_page 444 /444.html;
        location /444.html {}    

        #451 Unavailable For Legal Reasons
        error_page 451 /451.html;
        location /451.html {}

        #494 Request header too large
        error_page 494 /494.html;
        location /494.html {}

        #495 SSL Certificate Error
        error_page 495 /495.html;
        location /495.html {}
        
        #496 SSL Certificate Required
        error_page 496 /496.html;
        location /496.html {}        

        #497 HTTP Request Sent to HTTPS Port
        error_page 497 /497.html;
        location /497.html {}

        #500 Internal Server Error
        error_page 500 /500.html;
        location /500.html {}
        
        #502 Bad Gateway
        error_page 502 /502.html;
        location /502.html {}        

        #503 Service Unavailable
        error_page 503 /503.html;
        location /503.html {}
        
        #504 Gateway Timeout
        error_page 504 /504.html;
        location /504.html {}

        #505 HTTP Version Not Supported
        error_page 505 /505.html;
        location /505.html {}
        
        #507 Insufficient Storage
        error_page 507 /507.html;
        location /507.html {}        

        #set trusted ip's that can foward header info
        set_real_ip_from 127.0.0.1;
        set_real_ip_from ::1;
        real_ip_header X-Real-IP;
        real_ip_recursive on;
        
        #nr-main-controler-http-endpoint used for all unknown and new logins
        location / {

                proxy_pass http://localhost:10000;

		        #Defines the HTTP protocol version for proxying
		        #by default it it set to 1.0.
		        #For Websockets and keepalive connections you need to use the version 1.1
		        proxy_http_version 1.1;

		        #Sets conditions under which the response will not be taken from a cache.
		        proxy_cache_bypass $http_upgrade;

		        #These header fields are required if your application is using Websockets
		        proxy_set_header Upgrade $http_upgrade;

		        #These header fields are required if your application is using Websockets
		        proxy_set_header Connection "upgrade";

		        #The $host variable in the following order of precedence contains:
		        #hostname from the request line, or hostname from the Host request header field
		        #or the server name matching a request.
		        proxy_set_header Host $host;

		        #Forwards the real visitor remote IP address to the proxied server
		        proxy_set_header X-Real-IP $remote_addr;

		        #A list containing the IP addresses of every server the client has been proxied through
		        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

		        #When used inside an HTTPS server block, each HTTP response from the proxied server is rewritten to HTTPS.
		        proxy_set_header X-Forwarded-Proto $scheme;

		        #Defines the original host requested by the client.
		        proxy_set_header X-Forwarded-Host $host;

		        #Defines the original port requested by the client.
		        proxy_set_header X-Forwarded-Port $server_port;

		        #proxy_set_header Authorization "";
		        #proxy_set_header X-Forwarded-User $remote_user;
                
                #if all of the proxied servers are down, this will return a 50x error (bad gateway) else tell nginx to intercept this error
                proxy_intercept_errors on; 
        }
#cameras
}

```

Now when I goto an invalid url I can have it handle the redirect to the homepage, that is the dashboard

 ![Screenshot from 2022-03-09 22-33-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e57b88b279425239776eff81d336bb98a53d93ae.jpeg)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 May 2022 03:31 UTC](https://discourse.nodered.org/t/cannot-get-error-handler-controling-http-status-codes/59627/2 "2022-05-09T03:31:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
