Jay Taylor's notes
back to listing indexProxy (nginx) shows a Bad gateway error
[web search]I have a service (docker registry) that runs on port 5000
, I have installed nginx to redirect http request from 8080
to 5000
. If I make a curl to localhost:5000
it works, but when I make a curl to localhost:8080
I get a Bad gateway error.
nginx config file:
upstream docker-registry {
server localhost:5000;
}
server {
listen 8080;
server_name registry.mydomain.com;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 0;
chunked_transfer_encoding on;
location / {
proxy_pass http://docker-registry;
}
location /_ping {
auth_basic off;
proxy_pass http://docker-registry;
}
location /v1/_ping {
auth_basic off;
proxy_pass http://docker-registry;
}
}
In /var/log/nginx/error.log
I have:
[crit] 15595#0: *1 connect() to [::1]:5000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: registry.mydomain.com, request: "GET / HTTP/1.1", upstream: "http://[::1]:5000/", host: "localhost:8080"
Any idea?
-
In my case, my service that I was proxying died (and I didn't realize it) in the middle of me using it. One second I was accessing it, the next second I got bad gateway. I had to restart the service. – Michael Plautz Feb 18 '17 at 4:17
I assume its a Linux box, so most likely SELinux is preventing the connection as there is no policy allowing the connection.
You should be able to just run
# setsebool -P httpd_can_network_connect true
and then restart nginx.
-
-
You just fixed my problem, even if you didn't fix hellb0y77's. SE_LINUX strikes again! – Wesley Burr Aug 25 '16 at 16:31
-
-
That worked for me too. Does anyone have any further information on what it's actually doing? I hate not knowing! – martinedwards Jun 16 '17 at 17:34
-
Upvoted and worked on centOs 7, can I ask what security issues this may open. I generally run a set of iptables rules which allow local traffic. Wondering what this effects. – edencorbin Jul 11 '17 at 0:41
Based on the error message, it makes me wonder if localhost:5000 is being resolved as an ipv6 address, which you may not want. You could try changing that to 127.0.0.1:5000
EDIT: In your proxy_pass line, it is possible you are missing part of the URL? Try adding $request_uri so it could be:
proxy_pass http://docker-registry/$request_uri;
or probably:
proxy_pass http://docker-registry$request_uri;
Not sure which one is most correct.
Another thing to consider. Your config indicates:
server_name registry.mydomain.com;
So, localhost:8080 may not be matched. For testing, you could change this to:
server_name registry.mydomain.com localhost;
Then the localhost:8080 would be matched, as well as your domain. I assume registry.mydomain.com is just an example and you would put your real server FQDN in there.
-
Not work, set
127.0.0.1:5000
and i have tried with onlyserver_name localhost
andserver_name registry.mydomain.com
(trying from another server in the same lan with hostnameregistry.mydomain.com
in /etc/hosts), and both, but nothing...same error – hellb0y77 Apr 18 '15 at 7:21 -
Whit registry.mydomain.com
[crit] 16839#0: *5 connect() to 127.0.0.1:5000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: registry.mydomain,com request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "localhost:8080"
, with localhost:[crit] 16839#0: *5 connect() to 127.0.0.1:5000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "localhost:8080"
– hellb0y77 Apr 18 '15 at 7:30
Your Answer
Not the answer you're looking for? Browse other questions tagged proxy nginx gateway or ask your own question.
asked |
3 years, 5 months ago |
viewed |
37,386 times |
active |
Related
Hot Network Questions
-
Offensive language/behavior from co-worker in online game
-
Why is Thugs of Hindostan misspelt?
-
Asking a professor to teach better
-
Is it possible to remove the smell from rice mistakenly stored in a detergent box?
-
7 fishermen caught exactly 100 fish and no two had caught the same number of fish. Then there are three who have together captured at least 50 fish.
-
What is Chirped Pulse Amplification, and why is it important enough to warrant a Nobel Prize?
-
How to make large brace and parenthesis thinner?
-
Why did Douglas Adams introduce conflict between Arthur and the mice into later versions of Hitchhiker's Guide?
-
Why would characters spend time answering imaginary questions to fictional hypotheticals?
-
The Thirteen Doors of Aj Noc'la
-
How do you deal with colleagues, acquaintances asking you for knowledge that you gained with months of effort?
-
Is this an old school copy protection device?
-
Metric accents in time signature
-
Are burned out highlights bad?
-
How can I make a hanging indent where a title is outside of a text frame?
-
Young colleague wants to resign; I would like him to stay
-
What to do about the NPC massacre?
-
What does the Venom symbiote subsist on?
-
How to simulate someone talking with a full mouth?
-
What does Kanye (Ye) West actually mean by "Abolish the 13th Amendment"?
-
Is there a way to query Visualforce pages that have "Require CSRF protection on GET requests" set to false?
-
Creepy film with tentacle alien attacking crew members in a vessel in space or underwater
-
Citizenship removed and deported to desolate Island, viable alternative for prison?
-
In a PvP arena, how can other characters deal with a Rogue with Expertise in Stealth?
site design / logo © 2018 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2018.10.2.31795
This site is not affiliated with Linus Torvalds or The Open Group in any way.