2016-12-27 22 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

相關問題