question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nginx "Bad gateway" after restarting TinyPilot

See original GitHub issue

There seems to be an issue where nginx will report "

Repro steps

  1. Start a TinyPilot device normally
  2. sudo service tinypilot restart
  3. Visit http://tinypilot/

Expected

TinyPilot web interface loads normally.

Actual

Nginx reports “Bad Gateway”

Workaround

Restart nginx:

sudo service nginx restart

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
Bramzorcommented, Aug 8, 2020

“Bad gateway” is actually a valid answer during the reboot and shouldn’t be confused with “Gateway Timeout”. A gateway timeout is that the service is running, but not providing an answer within the specified timeframe. Can be increased as mentioned by somik but this will not solve a “Bad gateway” issue. A Bad gateway happens when Nginx tries to connect to the service but for some reason, that port is not up, blocked or tcp session could not be set up or any other reason.

So I assume Nginx is running before the service is ready? For this, there are a few possible ways to avoid this:

  • (On service level) Start the nginx service after starting the end service by specifying an “After” in the .service file.
  • (On nginx level) Using something like “health_check interval=10 fails=3 passes=1” in nginx which might help, haven’t tried it myself yet. But this defines how long Nginx will see an origin as bad.
  • (On application level) When clicking on reboot, use Ajax requests to check if the backend is available again and than refresh the browser.
0reactions
mtlynchcommented, Aug 9, 2020

I’d see lines like this:

2020/08/08 20:57:14 [error] 12922#12922: *95 connect() failed (111: Connection refused) while connecting to upstream, client: 10.0.0.100, server: tinypilot, request: "GET / HTTP/1.1", upstream: "http://[::1]:8000/", host: "tinypilot"

But I confirmed a fix in https://github.com/mtlynch/ansible-role-tinypilot/pull/27

Read more comments on GitHub >

github_iconTop Results From Across the Web

502 Bad Gateway nginx/1.14.2 - TinyPilot
SSH to the IP address I get connection refused from an IP on the same subnet. Is this system required to have Internet...
Read more >
Fresh install, no joy: Nginx error 502 - TinyPilot
Fresh install, no joy: Nginx error 502 ... Error 502 on new install ... tinypilot restart mv: cannot stat '/home/tinypilot/.flask-secret-key': No such file ......
Read more >
can't connect - TinyPilot
502 Bad Gateway ... Enable SSH and run the following command. ... /home/tinypilot/old-flask-secret-key && \ sudo service tinypilot restart.
Read more >
TinyPilot
Issued a reboot to the system and after reboot, trying to connect to the web service results in a 502 bad gateway.
Read more >
Service doesn't start after install - TinyPilot
I see a 502 Bad Gateway error and the log shows the following: Connection refused) while connecting to upstream, client: 192.168.100.103, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found