arquivos .zip Nginx retornam 404

1

Eu configurei o Nginx como um proxy reverso para o Node e para servir meus arquivos estáticos e imagens enviadas por usuários.

Tudo está funcionando perfeitamente, exceto que não consigo entender por que o Nginx não consegue encontrar meus arquivos .zip. Aqui está o meu 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;

O tcp.conf contém configurações que permitem que o Nginx faça proxy em websockets. Eu não acredito que algo contido nele seja relevante para essa questão. Eu também quero adicionar que eu quero que os arquivos zip sejam um download forçado.

    
por Kenley Tomlin 23.11.2012 / 03:14

1 resposta

0

Tente reescrever da seguinte forma:

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

Além disso, se o acima não funcionar, como um hack, tente redefinir a raiz dentro do local:

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

Finalmente, pelo amor de $ DEITY, por favor, remova o aplicativo / zip dos seus tipos de gzip:

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;**

É inútil porque um arquivo .zip já está compactado!

    
por 24.11.2012 / 13:17