【发布时间】:2020-07-01 21:38:09
【问题描述】:
我的项目是 vue.js 上的一个 spa,它运行在 nginx 网络服务器上,位于数字海洋水滴上。 我需要向用户显示一个带有 500 错误的自定义页面,而不是默认的 500 错误消息。 我在 digitalocean 网站上找到了如何执行此操作的说明:https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04, 但不幸的是,这个食谱对我来说不起作用。 下面是我的 nginx 配置。
server {
listen 80;
listen [::]:80;
server_name my-app-domain.io;
return 302 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
ssl_certificate /etc/ssl/certs/ssl-cert-my-app-cf.pem;
ssl_certificate_key /etc/ssl/private/ssl-key-my-app-cf.pem;
server_name my-app-domain.io;
root /var/www/my-app-domain.io/dist;
index index.html index.htm index.nginx-debian.html;
auth_basic "Administrator's Area";
auth_basic_user_file /etc/nginx/.htpasswd;
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
ssi on;
root /usr/share/nginx/html;
index custom_50x.html
internal;
}
location /testing {
fastcgi_pass unix:/does/not/exist;
}
location / {
try_files $uri $uri/ /index.html;
}
}
server {
if ($host = my-app-domain.io) {
return 301 https://$host$request_uri;
}
listen 80;
}
【问题讨论】:
-
当您的 http 库检测到 http 响应的任何错误时,让您的路由器将您的 SPA 重定向到错误页面(组件)。
-
@Sphinx 我将更详细地解释我的案例:我使用内容交付的做法,当构建发生在服务器上时,我想向用户显示自定义 500。如果我制作 500通过组件的路由,这对我没有帮助,因为应用程序文件在构建期间将不可用,并且 Web 服务器返回 500。