I am running nginx/1.15.7 on Ubuntu 18.04. My setup is that I have nginx serving as a reverse proxy for a Python3 Flask application. I am trying to enable a single custom error.html for all major errors ( 401, 404, 502 ... etc. ). I have tried many examples found on Google, but I am unable to have nginx serve my custom error.html when I purposefully type in an invalid URI for my nginx server. I can, however, successfully view my error.html if I visit "/error.html.
How can I make this work?
My sites-enabled configuration file is shown below:
server {
# Define the server name, IP address, and/or port of the server
listen 80;
# Define the specified charset to the “Content-Type” response header field
charset utf-8;
# Specify one error page for all errors
error_page 400 /error.html;
error_page 401 /error.html;
error_page 403 /error.html;
error_page 404 /error.html;
error_page 500 /error.html;
error_page 503 /error.html;
error_page 504 /error.html;
# Create 1 error page to rule them all
location ~ /*error.html {
try_files error.html @error;
internal;
}
location @error {
root /var/www/localhost/html;
}
# Configure NGINX to deliver static content from the specified folder for main webapp
location /main-static {
alias /home/root/MainWebApp/static;
}
# Favicon
location = /favicon.ico {
alias /home/root/MainWebApp/static/favicon.ico;
}
# This is the main WebApp
location / {
# Define the location of the proxy server to send the request to
proxy_pass http://comp.local.com:9000;
# Redefine the header fields that NGINX sends to the upstream server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
# Define the maximum file size on file uploads
client_max_body_size 5M;
}
}