Upload progress module: "track_uploads" directive inside an "if" block.

Dave Rothlisberger dave at rothlis.net
Mon Jan 19 02:03:23 MSK 2009


Hi,

I am using nginx as a proxy in front of a mongrel cluster running a  
rails application.

I can't seem to get nginx to serve static files *and* use the upload  
progress module (I can achieve one or the other, but not both at the  
same time).

For example, if I use an "if" block so that requests for static files  
aren't passed to the mongrel cluster:

   location / {
       ...
       if (!-f $request_filename) {
           proxy_pass http://mongrel_cluster;
           track_uploads proxied 30s;
       }
   }

This gives the following error message:

   [emerg] 12265#0: "track_uploads" directive is not allowed here

If I try, instead:

   location / {
       ...
       if (!-f $request_filename) {
           proxy_pass http://mongrel_cluster;
       }
       track_uploads proxied 30s;
   }

I get the following error message:

   [emerg] 12266#0: "track_uploads" directive track_upload should be  
the last directive in the location, after either proxy_pass or  
fastcgi_pass

If I remove the "if" condition completely:

   location / {
       proxy_pass http://mongrel_cluster;
       track_uploads proxied 30s;
   }

That works, but then all requests are proxied to the mongrel cluster,  
even requests for static files, and even requests for the  
"maintenance.html" page which I put up (with a separate rewrite rule)  
when I want to take the mongrel cluster down for maintenance (rails  
developers will be familiar with this). The request for the  
"maintenance.html" file is sent to the mongrels, which are down,  
resulting in a "502 Bad Gateway" error. And even the request for my  
"50x.html" error page is proxied to the mongrel cluster (which is  
down) so users get the default nginx 502 error page.

Does anyone know of a way around this, or a better way to configure  
the proxy_pass to avoid this issue? Any help would be *much*  
appreciated.

My full nginx config file is pasted below.

Regards,
--Dave Rothlisberger.


user xxx xxx;
worker_processes 4;

pid /var/run/nginx.pid;

error_log  logs/error.log  notice;

events {
     worker_connections  1024;
}

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

     upload_progress proxied 1m;

     # This log format is compatible with any tool like awstats
     # that can parse standard apache logs.
     log_format main '$remote_addr - $remote_user [$time_local] '
                     '"$request" $status $body_bytes_sent  
"$http_referer" '
                     '"$http_user_agen" "$http_x_forwarded_for"';

     sendfile       on;
     tcp_nopush     on;
     tcp_nodelay    on;

     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;


     # Load balance to mongrels
     upstream mongrel_cluster {
         server 0.0.0.0:8000;
         server 0.0.0.0:8001;
     }

     server {
         listen 80;
         server_name xxxx.com
         root /home/xxxx/xxxx/current/public;
         access_log /home/xxxx/xxxx/shared/log/nginx.access.log main;
         error_page 500 502 503 504 /50x.html;
         client_max_body_size 50M; # Avoid attempts to overload the  
server

         # Rewrite rule: Display maintenance page if it exists
         # (capistrano disable task creates this maintenance page)
         # BUT allow the image in the maintenance page to be displayed
         if ($request_filename ~ ^/images/) {
             break;
         }
         if (-f $document_root/system/maintenance.html) {
             rewrite ^(.*)$ /system/maintenance.html last;
             break;
         }

         location / {
             index index.html index.htm;

             location ~ ^/(images|javascripts|stylesheets)/ {
                 expires 10y;
             }

             if (-f $request_filename) {
                 break;
             }

             # Directly serve cached pages
             if (-f $request_filename.html) {
                 rewrite (.*) $1.html break;
             }

             # Otherwise let mongrel handle the request
             #if (!-f $request_filename) {  # Commented because of  
"track_uploads" problem
                 proxy_pass http://mongrel_cluster;
                 track_uploads proxied 30s;
             #}

             location ^~ /upload_progress {
                 report_uploads proxied;
             }
         }
     }
}






More information about the nginx mailing list