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

时间:2013-08-20 08:25:03

标签: nginx reverse-proxy

我在两台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;
  }
}

1 个答案:

答案 0 :(得分:0)

你正在使用免费版吗?

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