[help] nginx as reverse proxy for multimedia files
dewaforex
nginx-forum at nginx.us
Sun Dec 12 05:01:18 MSK 2010
Hi,
I'm new with nginx, just installed nginx for multimedia files and
dynamic files still using apache
I had folder "dl" for my multimedia files mp3.
And only user that had cookies that generate from download page can
access it and prevent a country to access it but allow server ip to
access it as the server ip is from same country that is restricted and
prevent hotlinking my files too.
When using apache was not problem I can used htaccess
This is the htaccess code
[code]
Options +FollowSymLinks
GeoIPEnable On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(HK)$
RewriteCond %{REMOTE_ADDR} !^x\.x\.x\.x$
RewriteRule ^(.*)$ http://domain.com/ [L]
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !(^|(.+;)*)id=valid(;.*|$) [OR,NC]
RewriteCond %{HTTP_REFERER} !(^http://domain\.com|^about:blank) [NC]
RewriteCond %{REMOTE_ADDR} !^x\.x\.x\.x$
RewriteRule ^(.*)$ - [R=404]
[/code]
With this setting, it's seem the cookies and country restriction is
working but the download file is accessing using nginx and apache so the
download is not smoothly, a few second run and than it's seem stop for a
few second and then start again.
I check at the log, the file through using nginx and apache that I was
suppose only using nginx.
[code]
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
gzip on;
geoip_country /usr/local/share/GeoIP/GeoIP.dat;
geoip_city /usr/local/share/GeoIP/GeoIPCity.dat;
map $geoip_country_code $sb_allow {
default yes;
hk no;
}
server {
listen 80;
server_name domain.com www.domain.com;
location / {
proxy_pass http://127.0.0.1:81/;
include /etc/nginx/conf.d/proxy.conf;
}
location ~*
^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$
{root /var/www/html/domain;}
location dl/ {
if ($sb_allow = no) {
return 403;}
if ($http_cookie !~* "(^|(.+;)*)id=valid(;.*|$)"){
return 404;}
}
}
}
[/code]
but if add mp3 file type in this setting
[code]
location ~*
^.+\.(mp3|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$
{root /var/www/html/domain;}
[/code]
Files accessing through nginx but the rules for cookie,country
restriction and hot linking are not working.
As I'm new with nginx I don't how to solve it
I hope anyone can help me.
Thank you
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,157892,157892#msg-157892
More information about the nginx
mailing list