【发布时间】:2015-11-05 08:03:48
【问题描述】:
我正在通过 Nginx 代理服务器运行多个 ExpressJS Node 应用程序,并且每当我的用户尝试下载文件时都会引发 EPIPE 错误。这不会发生在我的本地设置上(除了代理服务器之外,它与服务器相同),所以我认为这与我的 Nginx 配置有关。
这是我的 Nginx 配置:
/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;
}
ExpressJS 服务器正在使用以下代码发送下载:
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);
}
});
该代码和其他所有内容在我的本地 git 存储库上都可以正常工作,但是当我从那里推送并在服务器端拉取时,网站会启动并尖叫 - 它在用户端超时并给我一个 EPIPE 错误控制台。我正在运行 Node.js 4.2.1 版和 ExpressJS 4.13.3 版。
【问题讨论】:
标签: node.js express nginx proxy reverse-proxy