Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have set up Nginx as a reverse proxy for Node and to serve my static files and user uploaded images.

Everything is working beautifully except that I can't understand why Nginx can't find my .zip files. Here is my nginx.conf.

    user nginx;
    worker_processes 1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events {
   worker_connections 1024;
    }

    http {

include mime.types;
proxy_cache_path /var/www/web_cache levels=1:2 keys_zone=ooparoopaweb_cache:8m     max_size=1000m inactive=600m;

sendfile on;

upstream *******_node {
    server 172.27.198.66:8888 max_fails=3 fail_timeout=20s;
    #fair weight_mode=idle no_rr
}

upstream ******_json_node {
    server 172.27.176.57:3300 max_fails=3 fail_timeout=20s;
}

server { #REDIRECT ALL HTTP REQUESTS FOR FRONT-END SITE TO HTTPS
    listen 80;
    server_name *******.com www.******.com;

    return 301 https://$host$request_uri;

}

server { #MOBILE APPLICATION PROXY TO NODE JSON
    listen 3300 ssl;
    ssl_certificate /*****/*******/json_ssl/server.crt;
    ssl_certificate_key /*****/******/json_ssl/server.key;

    server_name json.*******.com;

    location / {    
        proxy_pass http://******_json_node;
        proxy_redirect off;
        proxy_set_header Host $host ;
        proxy_set_header X-Real-IP $remote_addr ; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; 
        proxy_set_header X-Forwarded-Proto https;
        client_max_body_size 20m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90s;
        proxy_send_timeout 90s;
        proxy_read_timeout 90s;
        proxy_buffers 32 4k;
    }
}

server { #******.COM FRONT-END SITE PROXY TO NODE WEB SERVER
    listen 443 ssl;
    ssl_certificate /***/***/web_ssl/********.crt;
    ssl_certificate_key /****/*****/web_ssl/myserver.key;

    server_name mydomain.com www.mydomain.com;

    add_header Strict-Transport-Security max-age=500;

    location / {
        gzip on;
        gzip_types text/html text/css application/json application/x-javascript;
        proxy_pass http://mydomain_node;
        proxy_redirect off;
        proxy_set_header Host $host ; 
        proxy_set_header X-Real-IP $remote_addr ; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; 
        proxy_set_header X-Forwarded-Proto https;
        client_max_body_size 20m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90s;
        proxy_send_timeout 90s;
        proxy_read_timeout 90s;
        proxy_buffers 32 4k;
    }
}

server { #ADMIN SITE PROXY TO NODE BACK-END
    listen 80;

    server_name admin.mydomain.com;

    location / {
        proxy_pass http://mydomain_node;
        proxy_redirect off;
        proxy_set_header Host $host ; 
        proxy_set_header X-Real-IP $remote_addr ; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
        client_max_body_size 20m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90s;
        proxy_send_timeout 90s;
        proxy_read_timeout 90s;
        proxy_buffers 32 4k;
    }
}

server { # SERVES STATIC FILES

    listen 80;
    listen 443 ssl;

    ssl_certificate /**/*****/server.crt;
    ssl_certificate_key /****/******/server.key;

    server_name static.domain.com;
    access_log static.domain.access.log;

    root /var/www/mystatic/;

    location ~*\.(jpeg|jpg|png|ico)$ {

        gzip  on;
        gzip_types text/plain text/css application/json application/x-javascript text/xml
        application/xml application/rss+xml text/javascript image/svg+xml
        application/vnd.ms-fontobject application/x-font-ttf font/opentype image/png image/jpeg
        application/zip;
        expires 10d;
        add_header Cache-Control public;

    }

    location ~*\.zip {
        #internal;
        add_header Content-Type "application/zip";
        add_header Content-Disposition "attachment; filename=gamezip.zip";
    }
}
}

include tcp.conf;

Tcp.conf contains settings that allow Nginx to proxy websockets. I don't believe anything contained within it is relevant to this question. I also want to add that I want the zip files to be a forced download.

share|improve this question
    
May I add that is the zip file is renamed to .jpeg/.png/.jpg/.ico then nginx will find the file. –  Kenley Tomlin Nov 23 '12 at 2:18
    
When looking at the logs I see that nginx is trying to open a file at 012/11/23 11:28:28 [error] 9239#0: *1298 open() "/usr/local/nginx/html/gamezip/G3zZ4pBq0BCeKb3o13EPKC4AaT63JvbnwOwQsV4p.zip" failed (2: No such file or directory), client: 121.140.215.179, server: static.ooparoopa.com, request: "GET /gamezip/G3zZ4pBq0BCeKb3o13EPKC4AaT63 but I have specified that it is to look in /var/www/gamezip. –  Kenley Tomlin Nov 23 '12 at 2:31
1  
gzip_types ... image/png image/jpeg application/zip;! Do you realize what you are doing? –  VBart Nov 23 '12 at 18:51

1 Answer 1

up vote 0 down vote accepted

Try rewriting it like this:

location ~ .*\.zip$ {
    add_header Content-Type "application/zip";
    add_header Content-Disposition "attachment; filename=gamezip.zip";
}

Also, if the above does not work, as a hack, try redefining the root inside the location:

location ~ .*\.zip$ {
    root /var/www/mystatic/;
    add_header Content-Type "application/zip";
    add_header Content-Disposition "attachment; filename=gamezip.zip";
}

Finally, for the love of $DEITY, please remove application/zip from your gzip types:

gzip_types text/plain text/css application/json application/x-javascript text/xml
    application/xml application/rss+xml text/javascript image/svg+xml
    application/vnd.ms-fontobject application/x-font-ttf font/opentype image/png image/jpeg **application/zip;**

It is useless since a .zip file is already compressed!

share|improve this answer
    
Thanks I have taken your suggestions. –  Kenley Tomlin Nov 27 '12 at 5:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.