简体   繁体   中英

EPIPE Error with ExpressJS, nginx proxy server

I am running multiple ExpressJS Node apps through an Nginx proxy server, and am getting an EPIPE Error thrown whenever my users try to download a file. This does not happen on my local setup (which is identical to the server's except for the proxy server), so I figure it has something to do with my Nginx configuration.

Here are my Nginx configs:

/etc/nginx/nginx.conf

user                    www www;
worker_processes        1;
error_log               /home/alex/logs/error.log;
pid                     /var/run/nginx.pid;
worker_rlimit_nofile    8192;

events {
    worker_connections  4096;  ## Default: 1024
}

http {
    include         mime.types;
    index           index.html index.htm index.php;
    default_type    application/octet-stream;
    log_format      main '$remote_addr - $remote_user [$time_local]  $status '
                         '"$request" $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for"';
    access_log      /home/alex/logs/access.log  main;
    sendfile        on;
    tcp_nopush      on;
    gzip            on;

    server_names_hash_bucket_size 128; # this seems to be required for some vhosts

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  example.com;

    # log access and stuff
    access_log  /home/alex/logs/example-site.log  main;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    # Proxy to the NodeJS server
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8999;
    }

    # redirect server error pages to their HTML
    include /etc/nginx/errpages.conf;
}

The ExpressJS server is sending the download using the following code:

app.get('/citrite/p/:patch', function(req, res)
{
    if(set.citFiles.indexOf(req.params.patch) == -1)
    {
        res.send(mbuild.get404());
    }
    else
    {
        track.incrViewcount(req.params.patch, 'citrite');
        res.download(set.citDir + '/' + req.params.patch, files.doneSaving);
    }
});

That code and everything else works fine on my local git repo, but when I push from there and pull on the server-side, the site kicks and screams - it times out on the user's end and gives me an EPIPE error in the console. I am running Node.js version 4.2.1 and ExpressJS version 4.13.3.

I figured out what the problem was: apparently, having sendfile set to on is what was causing the downloads to stall, and turning that off (specifically, removing the directive in the config) fixed the issue. Not exactly sure why this would interfere, but getting rid of the setting cleared things up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM