在尝试在我的一个网站上设置 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;
}
这里可能有什么问题?
答案就在这里: https ://stackoverflow.com/questions/37860639/nginx-custom-404-css-js-not-found 这是将 404.html 中的 css/js 文件位置编辑为绝对位置的问题 - 在无论站点位置如何,都会使用该案例文件。