我想显示one custom maintenance page
。all errors
我应该在下面的 nginx 设置中放入什么代码?我的 nginx 设置文件位于/etc/nginx/conf.d/default.conf
。
server {
listen 80;
listen [::]:80;
server_name myip;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://myapp:8000;
}
location /static/ {
alias /myapp/static/;
}
location /media/ {
alias /myapp/media/;
}
}
下面是我的maintenance.html
文件。
<!DOCTYPE html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
<article>
<h1>We’ll be back soon!</h1>
<div>
<p>Sorry for the inconvenience. We’re performing some maintenance at the moment.</p>
</div>
</article>
我maintenance.html
在浏览器上看起来像这样。
答案1
将您的
maintenance.html
文件放在/var/www/html/maintenance.html
。将
error_page line
和location block
显示放在下面。
server {
listen 80;
listen [::]:80;
server_name myip;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://myapp:8000;
}
location /static/ {
alias /myapp/static/;
}
location /media/ {
alias /myapp/media/;
}
##### Put this code #####
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /maintenance.html;
location = /maintenance.html {
internal;
root /var/www/html;
}
##########################
}
我提到本网站解决你的问题。网站教你如何为所有错误显示一个自定义错误页面。我还参考了本网站获取maintenance.html的代码。