Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 'upstream prematurely closed connection while reading response header from upstream' while using nginx proxy #458

Closed
deities-online opened this issue Apr 23, 2020 · 5 comments

Comments

@deities-online
Copy link

deities-online commented Apr 23, 2020

I got a strange error while proxy from nginx to tide server.

steps:

  1. my app using tide as server and bound on 127.0.0.0:10086
  2. execute curl http://127.0.0.1:10086/test/code, everything is fine. and trace log of my app is:
{"level":10,"time":1587640196537,"msg":"registering with poller"}
{"level":30,"time":1587640196538,"msg":"spawn","task_id":"1","parent_task_id":"2"}
{"level":10,"time":1587640196539,"msg":"IN => GET /test/code"}
{"level":10,"time":1587640196539,"msg":"Server response encoding: start"}
{"level":10,"time":1587640196539,"msg":"Server response encoding: fixed length body"}
{"level":10,"time":1587640196541,"msg":"deregistering handle with poller"}
  1. config nginx proxy like below script:
server{
listen 443 ssl;
server_name my.host.com;
ssl_certificate /root/cert/spa.pem;
ssl_certificate_key /root/cert/spa.key;
ssl_session_timeout 5m;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:10086/;
proxy_redirect off;
}
}
  1. restart nginx.
  2. execute curl https://my.host.com/test/code ,502 Bad Gateway get returned. error log in /var/log/nginx/error.log is upstream prematurely closed connection while reading response header from upstream

and trace log of my app is:

{"level":30,"time":1587640196541,"msg":"completed","task_id":"1"}
{"level":10,"time":1587640212174,"msg":"registering with poller"}
{"level":30,"time":1587640212174,"msg":"spawn","parent_task_id":"2","task_id":"3"}
{"level":10,"time":1587640212175,"msg":"deregistering handle with poller"}

After change to using actix-web as server, both
curl http://127.0.0.1:10086/test/code and curl https://my.host.com/test/code works fine.

Is this an issue of tide or http-service-1?

@yoshuawuyts
Copy link
Member

@deities-online it's hard to tell just from this log; could you perhaps share more details? In particular versions of tide, async-h1, async-std, and http-types would be relevant to know. You can find these in your Cargo.lock file. Thanks!

@deities-online
Copy link
Author

@deities-online it's hard to tell just from this log; could you perhaps share more details? In particular versions of tide, async-h1, async-std, and http-types would be relevant to know. You can find these in your Cargo.lock file. Thanks!

@yoshuawuyts Sorry, forgot provide version information.

I was using master brach of tide. compile env has been overwrite.

I reproduce this issue today:

execute commands:

Screen Shot 2020-04-24 at 10 40 57

output log of pm2:
Screen Shot 2020-04-24 at 10 39 46

os is Centos 7, nginx version refer to first image. and the Cargo.lock file is:
Cargo.lock.txt

If any information need, please let me know.

@jbr
Copy link
Member

jbr commented Apr 24, 2020

@deities-online Here's what we believe is the fix:
Add proxy_http_version 1.1; to your nginx stanza. Please report back if that resolves the problem for you!

@deities-online
Copy link
Author

@deities-online Here's what we believe is the fix:
Add proxy_http_version 1.1; to your nginx stanza. Please report back if that resolves the problem for you!

@jbr It works, Thanks!

It would be better to add some warning info in log.

@jbr
Copy link
Member

jbr commented Apr 25, 2020

@deities-online Good point about logging. Added #470 to reflect that need and closing this as resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants