# Nginx as reverse proxy for multimedia files

**URL:** <https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-multimedia-files/200447>\
**Category:** NGINX\
**Created:** [December 12, 2010, 3:03am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-multimedia-files/200447 "2010-12-12T03:03:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 12, 2010, 3:03am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-multimedia-files/200447/1 "2010-12-12T03:03:08Z")

</div>

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

```auto
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]
```

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.

```auto
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;}
        }
  }
}
```

but if add mp3 file type in this setting

```auto
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;}
```

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:

> **[\[help\] nginx as reverse proxy for multimedia files](https://forum.nginx.org/read.php?2,157892,157892#msg-157892)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![dewaforex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e480ec/32.png) [@dewaforex](https://www.ruby-forum.com/u/dewaforex)\
**Post date:** [December 13, 2010, 12:52am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-multimedia-files/200447/2 "2010-12-13T00:52:48Z")

</div>

Problem with download is not run smoothly with first setting is fixed  
It’s because the permission of this folder  
"/usr/local/nginx/proxy\_temp/

But still the file using nginx and apache when using first setting.

Posted at Nginx Forum:

> **[Re: \[help\] nginx as reverse proxy for multimedia files](https://forum.nginx.org/read.php?2,157892,158055#msg-158055)**
>
> 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...
