2016-12-27 59 views
0

当创建一个带有nodejs的网站时。在这个网站上,我有一个可以将图像上传到服务器的页面。我在我的电脑上测试了它的工作正常。在将其部署到服务器后,它无法正常工作。我读了日志。我同时从访问和错误日​​志中获得了两个。NodeJS无法上传文件导致上游过早关闭连接

这是一个error.log中

upstream prematurely closed connection while reading response header from upstream , client: xx.xx.xx.xx, server: example.com, request: "POST /admin/place/thumbnanil/upload HTTP/1.1", upstream: "http://127.0.0.1:3002/admin/place/thumbnanil/upload", host: "example.com", referrer: "https://example.com/admin/place/detail" 

这是一个access.log的

POST /admin/place/thumbnanil/upload HTTP/1.1" 502 583 "https://example.com/admin/place/detail" 

这是我的Nginx虚拟主机

upstream example { 
    server 127.0.0.1:3002; 
    keepalive 8; 
} 

server { 
    listen     80; 
    server_name    example.com; 
    return     301 https://$server_name$request_uri; 
} 

server { 
    listen     443 ssl; 
    server_name    example.com; 
    ssl_certificate   /etc/letsencrypt/live/example.com/fullchain.pem; 
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem; 
    location/{ 
      proxy_pass  http://127.0.0.1:3002; 
      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 

      proxy_buffering on; 
      proxy_buffer_size 8k; 
      proxy_buffers 2048 8k; 
    } 
} 

我使用Ubuntu 14.04上AWS EC2。 的NodeJS v4.4.7

这是我使用后的网址:https://example.com/admin/place/thumbnanil/upload

+0

你可以发布你正在使用后的完整网址? –

+0

@AkshayKumar当然。 – Natsathorn

回答

0

试试这个,

location/{ 
    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 $scheme; 

    proxy_pass   http://localhost:3002/; 
    proxy_read_timeout 90; 
    proxy_buffering  off; 
    proxy_redirect  http://localhost:3002/ https://example.com/; 

} 
+0

不工作,先生,得到了同样的错误。 – Natsathorn

+0

已编辑现在试试 –

+0

我仍然得到了同样的错误,但这次我得到了有关文件夹权限的错误,我将修复它并重试。 – Natsathorn

相关问题