Skip to content

Instantly share code, notes, and snippets.

@gjuric
Created April 14, 2011 22:02
Show Gist options
  • Save gjuric/920669 to your computer and use it in GitHub Desktop.
Save gjuric/920669 to your computer and use it in GitHub Desktop.
ugly nginx rewrite
server {
listen IP-ADDRESS:80;
root /root/path;
location ^~ /img {
rewrite ^/img/([a-z0-9])([a-z0-9])([a-z0-9])(.*)$ /repository/images/$1/$2/$3/$1$2$3$4 last;
}
location /repository/images {
if (!-e $request_filename) {
rewrite ^/repository/images/(.)/(.)/(.)/(.*)$ /api/image.php?filename=$4;
proxy_pass http://IP-ADDRESS:8080;
break;
}
}
location ~* \.(?:jpe?g|gif|png|ico|css|js|pdf|flv|mp4|swf|mp3|zip)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location / {
proxy_pass http://IP-ADDRESS:8080;
}
}
server {
listen IP-ADDRESS:80;
root /root/path;
location ^~ /img {
rewrite ^/img/([a-z0-9])([a-z0-9])([a-z0-9])(.*)$ /repository/images/$1/$2/$3/$1$2$3$4;
if (!-e $request_filename) {
rewrite ^/repository/images/(.)/(.)/(.)/(.*)$ /api/image.php?filename=$4;
proxy_pass http://IP-ADDRESS:8080;
break;
}
expires max;
}
location /repository {
expires max;
}
# Serve static files directly
location ~* .+\.(txt|gif|jpg|png|jpeg|ico|css|js|pdf|flv|mp4|swf|mp3|zip)$
{
expires max;
}
location / {
proxy_pass http://IP_ADDRESS:8080;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment