Custom Error Page Settings via NGINX Balancer

When any error occurs, e.g. your application server is down or environment is stopped, a particular default error page is opened depending on the problem. You can substitute this error page with your own custom one in order to provide your end-users with some instructions or leave email to contact you. 

Your custom error page can be configured via NGINX balancer enabled in your environment. Note that it is added automatically if you use two or more application servers.

So, let’s examine how to customize the default error page regarding your requirements.

1. Go to your Jelastic dashboard, find the NGINX-balancer in your environment and click Config button next to it.

nginx config

2. In the opened configuration manager tab navigate to the conf.d folder and create or upload your custom error page (for example, error.html). Save the changes you’ve made.

custom error page

3. Then navigate to the conf > nginx-jelastic.conf file. It is not editable, so select all its content and copy it to the clipboard.

nginx jelastic conf


4. Then open
nginx.conf file (located in the same folder) and paste the text copied instead of include /etc/nginx/nginx-jelastic.conf; line (circled below).

nginx balancer configuration


This file is editable, so you will be able to specify all the configurations you need, and they will override the ones in
nginx-jelastic.conf file.


5. After that find the
server section of the configs pasted and add there the following strings, as it is shown in the picture.


error_page 403 404 500 502 503 504 /etc/nginx/conf.d/error.html;

proxy_intercept_errors on;

setting custom error page


6. Then change the necessary
error_page parameters using the code below:

location /error.html {
root   /etc/nginx/conf.d;                                                        
       }
                               location / {
                                               if ($cookie_SRVGROUP ~ group|common) {
                                                               proxy_pass http://$cookie_SRVGROUP;
                                                               error_page   500 502 503 504 = error.html;
                                               }
                                               if ($cookie_SRVGROUP !~ group|common) {
                                                               add_header Set-Cookie "SRVGROUP=$group; path=/";
                                               }
                                               proxy_pass http://default_upstream;
                                               add_header Set-Cookie "SRVGROUP=$group; path=/";
                               }
                               location @rescue {
                                               proxy_pass http://$cookie_SRVGROUP;
                                               error_page   500 502 503 504 = error.html;
                               }
                               location @recycle {
                                               proxy_pass http://default_upstream;
                                               add_header Set-Cookie "SRVGROUP=$group; path=/";
                               }

error page configs

7. Finally, Save the changes and Restart the Nginx.

Now if any error occurs, your customers will be redirected to your custom error page.


specify error page