templates - NGINX 关闭或重新加载时如何加载 HTML 模板?
问题描述
在构建应用程序时,我正在尝试找到一种方法来加载html
显示“服务器关闭”或类似内容的方法。
现在,我每次构建后端和前端时,如果我访问该站点,就会有几秒钟的时间看到以下模板:
我想自定义该页面或显示不同的模板:Server Down at the moment
或Building
我nginx.conf
的是以下。我应该将 403.html 模板加载的位置放在哪里?:这需要在我认为的构建文件夹之外,因为 403 页面在构建时出现。
server { # [ASK]: is this what's causing the problem ?
root /home/smiling/smiling-frontend/website/build; ## development build
index index.html;
server_name frontend.develop.smiling.be; ## development domain
charset utf-8;
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/xml+rss;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)\$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
location ~ /\.well-known {
allow all;
}
location ~ /\.ht {
deny all;
}
add_header Access-Control-Allow-Origin '*/';
add_header Access-Control-Allow-Headers 'origin, x-requested-with, content-type, accept, authorization';
add_header Access-Control-Allow-Methods 'GET, POST';
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/backend.develop.smiling.be/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/backend.develop.smiling.be/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
}
解决方案
你的最后一句话有点不一致......你喜欢不做某事,但仍然想做同样的事情。
您可以定义自己的页面或字符串以在错误时提供服务:
error_page 403 /403.html;
location = /403.html {
internal;
return 403 "Server Down at the moment"; # <- this could also contain an HTML string if your nginx defaults to text/html as content type.
}
您还可以将403.html
文件放在根文件夹中并跳过位置部分,以便在此处提供完整的 HTML 文件。
推荐阅读
- c - vxWorks 计时器:无法多次调用处理程序
- c - C - Marshaling/Unmarshaling Struct with htonl and ntohl
- microservices - 如何将 RDBMS 单体数据库转换为基于微服务架构的数据库
- spring - 如何在安装了 Spring Tool Suite 4 的 Eclipse 2018-12 中获取 Spring Explorer 视图?
- c# - 应用程序的 SQL Server 连接超时问题
- c# - 如何从键包含子字符串的字典中获取(键,值)的集合?
- java - java 可选:不必做嵌套 ifPresent() 的好方法
- java - 对话框后按已禁用
- git - 如何正确使用 git 别名中的参数?
- excel-formula - 嵌套 IF 语句中的参数过多