NGINX:js/css 不存在

NGINX:js/css 不存在

当我尝试在我的某个网站上设置 404 网页时,我找不到包含斜线的不存在链接的解决方案,例如,如果我尝试连接到https://supra.tf/anything,它将返回正确的页面,但尝试后https://supra.tf/anything/anything返回了正确的页面,但没有格式(即 css/js 文件)。这是我的 nginx 配置:

        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;
}

这可能存在什么问题?

答案1

答案就在这里: https://stackoverflow.com/questions/37860639/nginx-custom-404-css-js-not-found 这是将 404.html 中的 css/js 文件位置编辑为绝对位置的问题 - 在这种情况下,无论站点位置如何都会使用文件。

相关内容