Custom nginx error template

Hi,

I’ve tried telling nginx to use a custom template on 500 errors, but so far it continues to use the default:

I’ve defined this rule via a Trellis nginx-includes:

/trellis/nginx-includes/all/error-templates.conf.j2

# {{ ansible_managed }}

# Display custom server error template.
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
    root /usr/share/nginx/html;
    internal;
}

location /testing {
    fastcgi_pass unix:/does/not/exist;
}

The location /testing works (ignore the text, I just copied a default nginx template).
https://www.mydomain.test/testing

Screenshot 2020-09-06 at 12.09.44

However I use this url as my test to trigger an error 500 (because I have no sitemap). No use of the custom template.
https://www.mydomain.test/sitemap.xml

Screenshot 2020-09-06 at 12.11.25

1 Like

Still trying to figure this one out.

When I add item to: /trellis/nginx-includes/all/ such as my error-templates.conf.j2. Where does the contents of this end up on the server? Can’t find it in /etc/nginx/sites-enabled/ so far, but considering the /testing method worked, it must be somewhere.

I am re-provisioning after any change to the error-templates.conf.j2 too.

@JordanC26 did you get anywhere with this? I’m currently having issues trying to set up the same.

The contents of the templates you add end up in /etc/nginx/includes.d/includes.d/example.com/ and then included in /etc/nginx/sites-enabled/example.com.conf. I just can’t get a 500 or 503 error template working.

I’ve not made any progress on this so far. Still need to sort it too, hopefully we can get some attention to it.

Sorry to bump but any ideas on the original question here? I’m no further understanding why it’s not using my custom template.

This topic was automatically closed after 42 days. New replies are no longer allowed.