Bob C.
Bob C.

Reputation: 141

How do I use custom error pages with the Nginx stream module

I created a custom .conf file that includes the stream module in order to listen on port 443 and proxy to another server via tcp. It works as expected. However if the proxying server is offline, I want to return a custom error page. I've done this before within the http module but apparently the stream module does not support the error_page directive.

Is there any workaround?

Upvotes: 0

Views: 493

Answers (1)

Bob C.
Bob C.

Reputation: 141

I ended up employing a load balancing approach as shown here. The backup weighting makes sure all traffic will initially attempt to route to the first server. If the first server is offline, traffic will be routed to the second server. From there I just created an http server directive to listen on port 9443 and simply added 'index my_error_page.html' within the location block.

stream {
   upstream my_server {
        server x.xxx.xxx.xxx:10443;
        server 127.0.0.1:9443 backup;
   }

   server {
        listen 443;
        proxy_pass my_server;
   }
}

Upvotes: 1

Related Questions