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

I am having trouble serving zip files from my nginx server. I am testing this out by putting a zip file in the html root director (for simplicity) and then trying to download it.

When I go to the file location I get no response from the server, no 404 or other error, just the website index.html page. My nginx.conf is the basic default nginx:

#user www-data;
user admin;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rs$

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

Here is my site specific config. (I have replaced any identifying info with **). I am running a django via gunicorn from a sub director but the files I am trying to download are in the root directory which is serving html and php files without issue.

server {
        listen 80;
        listen 443 default_server ssl;

        server_name localhost;

        client_max_body_size    50M;
        sendfile                on;

        ssl_certificate /******;
        ssl_certificate_key ******;

        access_log /home/admin/******/vc_access.log;
        error_log  /home/admin/*******/vc_error.log;

        root /usr/share/nginx/www;
        index index.html index.htm;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /******/www;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}

        location /static/ { # STATIC_URL
                alias /home/admin/******/static/; # STATIC_ROOT
                expires 30;
        }

        location /******gunicorn******/ {
               access_log /home/*******/logs/gunicorn/access.log;
               error_log /home******/logs/gunicorn/error.log;
               alias /home/admin/*******;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Host $http_host;
               proxy_redirect off;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Scheme $scheme;
               proxy_pass http://127.0.0.1:8000;
               proxy_connect_timeout 900s;
               proxy_send_timeout 900s;
               proxy_read_timeout 900s;
        }

        location /******/protected {
                internal;
                #root /tmp/;
                alias /home/******/;
                #alias /tmp/;
        }
}
share|improve this question
1  
The server block relevant to your site - defined in your configuration (e.g. from /etc/nginx/sites-enabled/*) would be helpful in determining the problem, as those are 'site specific'. Please add the rest of your configuration to your question (especially any parts you might have changed). –  cyberx86 Nov 15 '12 at 12:49
    
@cyberx86 I have updated my question with my site specific config. –  Finglish Nov 15 '12 at 20:55
    
Increase your error_log verbosity (e.g. to debug, info, or notice) and check your logs to see what Nginx is doing. It would seem that Nginx cannot find the file you are requesting (it should be looking at /usr/share/nginx/www/yourfile.zip), so is serving the index.html instead (as per your try_files directive). –  cyberx86 Nov 15 '12 at 21:35

1 Answer 1

Have you tried commenting out

    location / (

I'm wondering if that is interfering with the sending of the zip file.

share|improve this answer

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.