Nginx as reverse proxy for multimedia files


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

Options +FollowSymLinks
GeoIPEnable On
RewriteCond %{REMOTE_ADDR} !^x\.x\.x\.x$
RewriteRule ^(.*)$ [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.

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;

        location / {
            include /etc/nginx/conf.d/proxy.conf;

        location ~*
{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

location ~*
{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:

Problem with download is not run smoothly with first setting is fixed
It’s because the permission of this folder

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

Posted at Nginx Forum: