如果维护页面存在,我正在寻找我的nginx服务器返回503。
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
server_name _;
client_max_body_size 100M;
location / {
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://0.0.0.0:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Return a 503 error if the maintenance page exists.
if (-f /var/www/xxx/shared/public/system/maintenance.html) {
return 503;
}
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# Redirect server error pages to the static page /50x.html
error_page 500 502 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Return a 503 error if the maintenance page exists.
error_page 503 @503;
location @503 {
# Serve static assets if found.
if (-f $request_filename) {
break;
}
# Set root to the shared directory.
root /var/www/xxx/shared/public;
rewrite ^(.*)$ /system/maintenance.html break;
}
}
这似乎是正确的,但它不起作用。我已经验证该文件位于正确的位置,但这不能按预期工作。我仍然得到相同的旧nginx错误页面。
我已经重新加载了它,但仍然有相同的响应。
编辑:放置整个conf文件。
答案 0 :(得分:1)
我在我的设置中使用这个片段
server {
root /var/www/html;
server_name my-awesome-website.com;
location / {
if (-f $document_root/underconstruction.html) {
return 503;
}
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /underconstruction.html break;
}
location @maintenance ~ \.(jpg|png) {
root /www/media;
}
}