Welcome! Log In Create A New Profile

Advanced

[help] nginx as reverse proxy for multimedia files

December 11, 2010 09:01PM
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
Subject Author Posted

[help] nginx as reverse proxy for multimedia files

dewaforex December 11, 2010 09:01PM

Re: [help] nginx as reverse proxy for multimedia files

dewaforex December 12, 2010 06:51PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 184
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready