nginx maintenance page

Arfon Smith lists at ruby-forum.com
Tue Jul 15 19:54:10 MSD 2008


I'm having a little trouble getting the Nginx maintenance pages working
as I'd like them to.

I have the following rewrite rule in my Nginx config file:

if (-f /software/shared/system/maintenance.html) {
  rewrite  ^(.*)$  /system/maintenance.html last;
  break;
}

The problem I'm having is that this maintenance page is only showing up
when the Rails application is still running in the background.  If I
kill the Rails app I get a 502 Bad Gateway error and checking the Nginx
error log I see that Nginx is asking the mongrels to server the
maintenance file (but they're not there as the application isn't
running!)

I've copied in my full config below.

Any help would be greatly appreciated!

Arfon

#user  nobody;
worker_processes  5;

pid  /software/shared/log/nginx.pid;
error_log   /software/shared/log/nginx.error.log;

events {
    worker_connections  1024;
}

http {
    include       /software/shared/config/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local]
$request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /software/shared/log/nginx.access.log  main;
    client_body_temp_path /software/shared/nginx/client_temp 1 2;
    proxy_temp_path /software/shared/nginx/proxy_temp 1 2;
    fastcgi_temp_path /software/shared/nginx/fastcgi_temp 1 2;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     off;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip              on;
    gzip_http_version 1.0;
    gzip_comp_level   2;
    gzip_proxied      any;
    gzip_types        text/plain text/html text/css
application/x-javascript text/xml application/xml application/xml+rss
text/javascript;

      upstream mongrel {
      server myapp.com:6641;
      server myapp.com:6642;
      server myapp.com:6643;
      server myapp.com:6644;
      server myapp.com:6645;
    }
    server {
        listen       6640;
        client_max_body_size 50M;
        root /software/shared/system;

        #access_log  log/host.access.log  main;
        rewrite_log on;

        if (-f /software/shared/system/maintenance.html) {
          rewrite  ^(.*)$  /system/maintenance.html last;
          break;

        }

       location / {

          # needed to forward user's IP address to rails
          proxy_set_header  X-Real-IP  $remote_addr;

          root   html;
          index  index.html index.htm;

          # needed for HTTPS
          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect false;
          proxy_max_temp_file_size 0;

          # If the file exists as a static file serve it directly
without
          # running all the other rewite tests on it
          if (-f $request_filename) {
            break;
          }

          # this is the meat of the rails page caching config
          # it adds .html to the end of the url and then checks
          # the filesystem for that file. If it exists, then we
          # rewite the url to have explicit .html on the end
          # and then send it on its way to the next config rule.
          # if there is no file on the fs then it sets all the
          # necessary headers and proxies to our upstream mongrels
          if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
          }

          if (!-f $request_filename) {
            proxy_pass http://mongrel;
            break;
          }
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list