Custom Error Page Settings via NGINX Balancer
The server will show the default error page in the event that an error arises in a particular context (such as attempting to visit a page that does not exist).
For example:
You can change the default error page to a personalized one that includes your contact email address and provides users with more detailed instructions. Here’s how to use your platform’s NGINX Load balancer to build up a custom error page:
Step 1. Locate the NGINX load balancer in your environment by going to your platform dashboard, then click the “Config” icon next to it.
Step 2. Select the /etc/nginx/conf.d folder in the configuration management tab that appears, and then either create a new custom error page or upload an existing one.
Step 3. The provided error.html file will be used for this lesson.
Step 4. After that, transfer the contents of the nginx-jelastic.conf file to the /etc/nginx directory. Then, replace the line that reads “include /etc/nginx/nginx-jelastic.conf;}” (highlighted in the image below) with this content by pasting it into the nginx.conf file.
You may now list every setting that is required.
Step 5. Find the “server” section in the copied configuration, and add the following lines to the default error_page settings:
error_page 403 404 500 502 503 504 /error.html;
proxy_intercept_errors on;
Step 6. Then, a little bit farther down, change the error page parameters under the “location” subsections.
location /error.html {
root /etc/nginx/conf.d;
internal;
}
location / {
if ($cookie_SRVGROUP ~ group|common) {
proxy_pass http://$cookie_SRVGROUP;
error_page 403 404 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=/";
}
Step 7. Extra adjustments are required if your website uses SSL, or if communications are made over HTTPS. If not, move on to this guide’s step 9. To the “servers” section of the /etc/nginx/conf.d/ssl.conf file, add the following lines:
proxy_intercept_errors on;
location /error.html {
root /etc/nginx/conf.d;
}
Step 8. Additionally, you’ll need to modify the /etc/nginx/conf.d/ssl.upstreams.inc file. Locate the specified condition and update it as follows:
if ($cookie_SRVGROUP ~ group|common) {
proxy_pass http://$cookie_SRVGROUP;
error_page 403 404 /error.html;
error_page 500 502 503 504 = @resque;
}
Step 9. Remember to restart the NGINX server to apply all the changes.
Step 10. That’s all! Now, try accessing any non-existing page within your domain.









