使用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;
}
}
我在AWS EC2上使用ubuntu 14.04。 NodeJS v4.4.7
这是我用于帖子的网址:https://example.com/admin/place/thumbnanil/upload
答案 0 :(得分: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/;
}