nginx rewrite of certain mime types and request processing order

technoplague nginx-forum at nginx.us
Mon Nov 5 11:00:32 UTC 2012


Hi,

Having following nginx virtual host config:

#==============================================
upstream cf-domain {
    server unix:/data/www/prod/domain.com/cf/cf-domain.sock;
}

server {
    listen 10.0.0.1:80;
    listen 127.0.0.1:28005;
    server_name cf.domain.com;
    index index.php index.html;
    root /data/www/prod/domain.com/cf/htdocs;
    charset utf-8;
    access_log /data/www/prod/domain.com/cf/logs/frontend/access.log;
    error_log /data/www/prod/domain.com/cf/logs/frontend/error.log;
    client_max_body_size 8m;

    # get rewrite
    location /get/ {
        rewrite ^/get/([^/]+)/([^/]+)$ /get/index.php?contid=$1 last;
    }

    # static content
    location ~* \.(jpg|jpeg|gif|css|png|js|swf|ico|rar|zip)$ {
        expires max;
        access_log off;
        log_not_found off;
    }

    location / {
         try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass cf-domain;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }

    #include conf.d/cf.dirs.conf;
}
#==============================================

The problem is with processing order and /get location rewrite. 
The request: http://cf.domain.com/get/68175/fingergr.swf returns 404,
instead by getting processed by /get location rewrite rule. This is because
swf is defined in (static content) location:

    # static content
    location ~* \.(jpg|jpeg|gif|css|png|js|swf|ico|rar|zip)$ {
        expires max;
        access_log off;
        log_not_found off;
    }

How is it possible to have /get location rewrite working together without
removing swf type from static content location? 

Thanks,
T

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,232503,232503#msg-232503



More information about the nginx mailing list