0

while trying to setup a 404 webpage on one of my sites I couldn't find a solution for non-existing links containing a slash, for instance if i try to connect to https://supra.tf/anything, it will return a correct page, but after trying https://supra.tf/anything/anything correct page is being returned, but with no formatting (aka css/js files). This is my nginx config:

        root /var/www/supra.tf/public_html;
        index index.html;
        server_name supra.tf;
        error_page 404 /404.html;
        location / {
                rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
                rewrite ^/(.*)/$ /$1 permanent;
                try_files $uri/index.html $uri.html $uri/ $uri =404;
        }
        location = /404.html {
                root /var/www/errors;
}
        location ~* ^.+\.(js|css|img)$ {
        root /var/www/errors;
        try_files $uri/index.html $uri.html $uri/ $uri =404;
}
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
        listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
        listen 443 ssl http2; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/supra.tf/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/supra.tf/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
        listen 80;
        listen [::]:80;
        server_name supra.tf;
        return 301 https://supra.tf$request_uri;
}

What could be a problem here?

Radosław Serba
  • 173
  • 1
  • 11
  • You need to look at the access log. If the requested URI is correct, then the problem is with the server configuration, if the URI is incorrect, then the problem is with the frontend (e.g. html file). – Richard Smith May 25 '20 at 07:24

1 Answers1

0

The answer was here: https://stackoverflow.com/questions/37860639/nginx-custom-404-css-js-not-found It was a matter of editing css/js file locations in 404.html to absolute ones - in that case files are used regardless of the site location.

Radosław Serba
  • 173
  • 1
  • 11