Need some help with rewrite rule translation

mailinglisten at simonhoenscheid.de mailinglisten at simonhoenscheid.de
Wed Jun 19 16:44:55 UTC 2013


Am 14.06.2013 14:11, schrieb mailinglisten at simonhoenscheid.de:
> I have found the point where my rules break,
> 
> I've had the following location on top, to enable browser caching for
> images, for one month:
> 
> #images give caching response for 1 month, browser will request after
> this period of time again
> location ~* \.(png|jpg|jpeg|gif)$ {
> expires 30d;
> log_not_found off;
> }
> This prevented the Rules to run.
> Is there a chance to get this functionality without breaking other 
> rules?
> 
> Simon
> 

This is still driving me mad. We need the expire header for images, but 
if we add the location above, our rules arent processed anymore. If we 
add the expire-header to the locations with the rewrite rules, the 
headers are ignored.
I would realy appreciate some help.

config:

server {
listen 1.2.3.4:80;
index index.php;
server_name static.examplecompany.com
access_log /var/log/nginx/static.examplecompany.com-access.log combined;
error_log /var/log/nginx/static.examplecompany.com-error.log notice;
root /usr/share/examplecompany/static;
#deny access to hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
#this breaks the rewrite rules, need to fix this soon, due to traffic
#        location ~* \.(png|jpg|jpeg|gif)$ {
#        expires 30d;
#       log_not_found off;
#        }

#images get caching response for 1 month, browser will request after 
this period of time again
#return 204 if favicon is requested, there is none, so we turn off 
logging too
location = /favicon.ico {
log_not_found off;
access_log off;
return 204;
}
# resized trailer images
location /image {
rewrite 
"^/image/resized/(\d+)/([0-9a-fA-F]{6}/|)(.+)_(\d+)(|m)x(\d+)(|m)(_.+|).(jpg|jpeg|png|gif)" 
/resized/getBySize.php?domainid=$1&objectid=$3&width=$4&height=$6&format=$9&random=$8&color=$2&maxwidth=$5&maxheight=$7 
last;
rewrite 
"^/image/logo_examplecompany_(|black_|lightgray_)([0-9a-fA-F]{6})(|_alpha)(|_big).gif" 
/images/pics/logo_examplecompany.php?color=$2&transparency=$3&picversion=$1&size=$4 
last;
rewrite "^/image/logo_examplecompany_(small|big)_([0-9a-fA-F]{6}).png" 
/images/pics/logo_examplecompany_png.php?color=$2&size=$1 last;
rewrite 
"^/image/(trailer|pcd)hints(|2)/([0-9a-fA-F]{6})_([a-z]{2}).(png|gif)" 
/images/trailerhints/trailerhint.php?what=$1&suffix=$2&color=$3&lang=$4&format=$5 
last;
# images for intext border
}
location /images {
rewrite 
"^/images/popup/colored/([0-9a-fA-F]{6})/bg_([a-z0-9_]+).(png|gif)" 
/images/popup/colored.php?color=$1&image=$2&format=$3 last;
rewrite "^/images/popup/(ppp[0-9]?)_([0-9a-fA-F]{6}).css" 
/images/popup/ppp_css.php?file=$1.css&color=$2 last;
}
location /media {
rewrite "^/media/(\d+)/(\d+)/(.+)\.(.{2,})$" 
/media/get.php?domainid=$1&objectid=$3&randomcachekey=$2 last;
}
# if file does not exist, assume its in the pattern somewhere
#this is almost ugly, there might be a better solution with try_file
location / {
try_files $uri @missing;
}
location @missing {
rewrite ^/(.*)\.(.*)$ /fullexamplecompany.php?file=$1.$2 last;
}
# for partners who configure their widgets on their own.
location /retargeting_v1 {
rewrite ^/retargeting_v1.js /jscollections.php?name=retargeting last;
}
location /recommendations_v1 {
rewrite ^/recommendations_v1.js /jscollections.php?name=recommendations 
last;
}
# to get single javascript modules
location /jsmodule {
rewrite ^/jsmodule/([_0-9A-Za-z\.,]+)/?([_A-Za-z0-9\[\]]+)?$ 
/jscollections.php?name=module&modules=$1&callback=$2 last;
}
# tinyexamplecompany integrations.
# publickey and optional file name extension .js
location /tiny {
rewrite ^/tiny/([a-zA-Z0-9]+)(\.js)?$ 
/tinyexamplecompany.php?publickey=$1&widgetname=belowArticle last;
rewrite ^/tiny/([a-zA-Z0-9]+)/([a-z][a-zA-Z_0-9]+)\.js$ 
/tinyexamplecompany.php?publickey=$1&widgetname=$2 last;
}
location /picturetrailers {
rewrite ^/picturetrailers/([a-zA-Z0-9]+)(\.js)?$ 
/tinyexamplecompany_picturetrailers.php?publickey=$1 last;
}
location /flytrailer {
rewrite ^/flytrailer/([a-zA-Z0-9]+)(\.js)?$ 
/fullexamplecompany.php?publickey=$1&widgetname=flytrailer&autoinit=1&file=x.js 
last;
}
location /fullexamplecompany {
rewrite ^/fullexamplecompany/([a-zA-Z0-9]+)\.js$ 
/fullexamplecompany.php?publickey=$1&file=x.js last;
rewrite ^/fullexamplecompany/([a-zA-Z0-9]+)/([a-z][a-zA-Z_0-9]+)\.js$ 
/fullexamplecompany.php?publickey=$1&widgetname=$2&file=x.js last;
}
location /async {
rewrite ^/async.js /async.php last;
}
location /demo {
rewrite ^/demo/([a-zA-Z0-9]+)\.js$ /demo.php?type=$1 last;
rewrite ^/demo/([a-zA-Z0-9]+)\/([a-z]+)\.js$ /demo.php?type=$1&lang=$2 
last;
}
location ~* \.php$ {
fastcgi_index   index.php;
fastcgi_pass 127.0.0.1:9000;
include         fastcgi_params;
fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param   SCRIPT_NAME        $request_filename;
}
}

Kind Regards
Simon




More information about the nginx mailing list