gpt4 book ai didi

nginx - 使用 NginX 作为反向代理时,如何回退到维护 url?

转载 作者:行者123 更新时间:2023-12-05 08:00:21 26 4
gpt4 key购买 nike

我在两个 IIS 服务器前设置了 Nginx。主要目标是负载平衡、ssl 卸载和缓存静态内容。

当所有上游服务器不可用或抛出 404 错误时,我遇到的真正困难是显示维护页面。我在我的 NginX 盒子上创建了一个 maintenance.html 文件,但无法加载它。我有时可以让它加载 IIS 404s,有时让它加载默认的 NginX 404。我真正想做的是,如果由于某种原因所有上游都关闭或抛出 404s 是为了向用户显示“维护”页面并最终在该页面中放入一些代码以提醒我所有上游服务器都已关闭。

这是我的配置:

# -------------------------------------------
# ACTUAL SITE WITH - SSL CERTIFICATE
#------------------------------------------


# Backend IIS Servers
upstream backend-iis {

# Health Checks
#healthcheck_enabled;
#healthcheck_delay 5000;
#healthcheck_timeout 5000;
#healthcheck_failcount 1;

# Upstream Servers
server ww1.pickle.com max_fails=3 fail_timeout=31s;
server ww2.pickle.com max_fails=3 fail_timeout=31s;
#server ww3.pickle.com;

# Sticky Sessions
#sticky;
#ip_hash;

}


# Server Configuration
server {

# Server Specific Settings
server_name www.pickle.com;
access_log /var/log/nginx/www.pickle.com.log ;
keepalive_timeout 5;
allow all;
server_tokens off;
gzip on;
gzip_vary on;

# SSL Settings (with SPDY 2)
ssl on;
listen 443 ssl spdy;
ssl_certificate /usr/share/nginx/ssl-certs/pickle_com/pickle_basic.crt;
# ssl_certificate /usr/share/nginx/ssl-certs/pickle_com/pickle_ev.crt;
ssl_certificate_key /usr/share/nginx/ssl-certs/pickle_com/pickle.com.key;
ssl_session_timeout 15m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;




# Proxy Pass to: backend-iis
location / {

#root /usr/share/nginx/sites/pickle-down/;

# Proxy Header to Keep Ip Address and Hostname
proxy_redirect off;
proxy_set_header Host "www.pickle.com";
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 to Backend IIS Servers
proxy_pass http://backend-iis;
# proxy_next_upstream error timeout http_404;
proxy_temp_path /usr/share/nginx/temp;

#Intercept Proxy Errors (show Nginx Error Pages)
#proxy_intercept_errors on;
error_page 404 500 502 503 504 = @maintenance;

}


# Proxy Pass to: backend-iis
location @maintenance {
internal;
root /usr/share/nginx/sites/pickle-down;
index maintenance.html index.html index.htm;
allow all;

}



error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

error_page 404 /404.html;
location = /usr/share/nginx/sites/pickle-down/404.html {
root html;
}
}

最佳答案

您使用的是免费版吗?

我认为您正在寻找的是名为 NGINX Plus 的非免费版本。 .

关于nginx - 使用 NginX 作为反向代理时,如何回退到维护 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18330305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com