3 messages in ru.sysoev.nginxRe: Image hotlinking rewrite
FromSent OnAttachments
Jan ŚlusarczykJun 14, 2007 1:53 am 
Igor SysoevJun 14, 2007 2:04 am 
Jan ŚlusarczykJun 14, 2007 9:20 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Image hotlinking rewriteActions...
From:Igor Sysoev (is-G@public.gmane.org)
Date:Jun 14, 2007 2:04:47 am
List:ru.sysoev.nginx

On Thu, Jun 14, 2007 at 10:53:40AM +0200, Jan ??lusarczyk wrote:

I'm using nginx to serve static files and proxy the dynamic requests to apache in the backend. It works very good and allowed me to free a lot of memory. Now | need to fight bandwidth staling on one of our servers and I can't solve the problem on my own.

This is the vhost config:

server { listen x.x.x.x:80; server_name www.servername.com www.otherservername.com; access_log /var/log/nginx/www.servername.com.access.log combined; # vbulletin attachment rewrites location ~* ^.+.(attachments|customavatars|archive) { proxy_pass http://apache; include /etc/nginx/proxy.conf; } location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|rar|bz2|doc|xls| exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ { root /var/www/hosts/www.servername.com; expires 1d; } location / { proxy_pass http://apache; include /etc/nginx/proxy.conf; } }

I need to redirect requests for images from specific hosts (I will compile the names every couple of days manually) to a specific file (ie. do_not_steal_bandwidth.gif). Can you help me with this?

If you need to redirect referers from spefic site only, then you may use map:

http {

map $referer $forbidden {

hostnames; default 0;

*.hotlink1.com 1; www.hotlink2.com/ 1; .hotlink3.com/ 1;

include hotlink.conf; }

server {

set $referer ""; if ($http_referer ~* '^http://([^:/]+)') { set $referer $1; }

location ...

location ~* ^.+\.(jpg|jpeg|gif ... {

if ($forbidden) { rewrite ^ http://...; }

root ... ... }

hotlink.conf:

*.hotlink4.com 1; www.hotlink5.com/ 1; .hotlink6.com/ 1;