# Connect() failed (111: Connection refused) while connecting to upstream

**URL:** <https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936>\
**Category:** NGINX\
**Created:** [December 3, 2012, 9:08pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936 "2012-12-03T21:08:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 3, 2012, 9:08pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/1 "2012-12-03T21:08:46Z")

</div>

Can’t figure out why I keep getting 502 bad gateway nginx error. Here is  
the  
error from nginx error log.

2012/12/03 19:30:21 [error] 20650#0: \*939328 connect() failed (111:  
Connection refused) while connecting to upstream, client: 70.94.18.35,  
server: [demo.domain.com](http://demo.domain.com), request: “GET /assets/js/msgFBmodal.js  
HTTP/1.1”,  
upstream: “[http://108.166.94.94:7080/assets/js/msgFBmodal.js](http://108.166.94.94:7080/assets/js/msgFBmodal.js)”, host:  
“[demo.domain.com](http://demo.domain.com)”, referrer:  
“[http://demo.domain.com/register/user\_profile](http://demo.domain.com/register/user_profile)”

I’m on a rackspace cloud sever, centos.

Posted at Nginx Forum:

> **[connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233519#msg-233519)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 9:19pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/2 "2012-12-03T21:19:17Z")

</div>

On 3 December 2012 20:08, Gallitin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can’t figure out why I keep getting 502 bad gateway nginx error. Here is the  
> error from nginx error log.
> 
> 2012/12/03 19:30:21 [error] 20650#0: \*939328 connect() failed (111:  
> Connection refused) while connecting to upstream, client: 70.94.18.35,  
> server: [demo.domain.com](http://demo.domain.com), request: “GET /assets/js/msgFBmodal.js HTTP/1.1”,  
> upstream: “[http://108.166.94.94:7080/assets/js/msgFBmodal.js](http://108.166.94.94:7080/assets/js/msgFBmodal.js)”, host:  
> “[demo.domain.com](http://demo.domain.com)”, referrer: “[http://demo.domain.com/register/user\_profile](http://demo.domain.com/register/user_profile)”

The error message of “Connection refused” would seem to be pretty  
self-explanatory … 🙂  
What about it is surprising you?

## J

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 9:21pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/3 "2012-12-03T21:21:38Z")

</div>

I didn’t understand why it’s refused? Where can I see why it was  
refused?

Posted at Nginx Forum:

> **[Re: connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233522#msg-233522)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 9:22pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/4 "2012-12-03T21:22:13Z")

</div>

On Mon, Dec 03, 2012 at 03:08:09PM -0500, Gallitin wrote:

Hi there,

> Can’t figure out why I keep getting 502 bad gateway nginx error.

Can your nginx access the server you have configured it to?

> 2012/12/03 19:30:21 [error] 20650#0: \*939328 connect() failed (111:  
> Connection refused) while connecting to upstream, client: 70.94.18.35,  
> server: [demo.domain.com](http://demo.domain.com), request: “GET /assets/js/msgFBmodal.js HTTP/1.1”,  
> upstream: “[http://108.166.94.94:7080/assets/js/msgFBmodal.js](http://108.166.94.94:7080/assets/js/msgFBmodal.js)”, host:  
> “[demo.domain.com](http://demo.domain.com)”, referrer: “[http://demo.domain.com/register/user\_profile](http://demo.domain.com/register/user_profile)”

What do you get when you do

curl -i [http://108.166.94.94:7080/assets/js/msgFBmodal.js](http://108.166.94.94:7080/assets/js/msgFBmodal.js)

from the nginx server? (That’s not exactly the same as nginx would do,  
but the error message should be instructive.)

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 9:45pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/5 "2012-12-03T21:45:00Z")

</div>

On Mon, Dec 03, 2012 at 03:29:19PM -0500, Gallitin wrote:

Hi there,

> Via SSH? Yes I can do this.

Yes, so long as you are running curl on the same machine that nginx is  
running on, it should be a valid network test.

> When I do that it says
> 
> HTTP/1.1 404 Not Found

> Apache Server at 108.166.94.94 Port 7080

Ok, that suggests that there is a listener on the host:port that nginx  
is trying to access. If you add "-H Host:demo.domain.com " to the curl  
command (just after "-i "), you will more closely mimic what nginx  
should  
be doing – that might show you the correct content.

> No if I do:  
> curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)
> 
> It returns the page code from that file.

I’m unsure what you mean here.

If it is “now it is all working”, then that’s good and the most likely  
reason for the problem was that apache was not running, or was  
firewalled,  
when you first tested and that has now been fixed.

If it is “here is a similar thing that is working, but my test case is  
not”, then can you provide enough of the nginx.conf to allow the test  
be reproduced? Probably, that will be just the location{} block that has  
the proxy\_pass that is used in the request, plus the relevant upstream{}  
definition if there is one, plus whatever config is in that server{}  
but outside all location{}s.

(Or just include the whole nginx config.)

Cheers,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 10:32pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/6 "2012-12-03T22:32:55Z")

</div>

Sorry for the grammar error.

If I do curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)  
it returns the code from the msgFBmodal.js page. Yet if I hit the page  
via  
browser I still receive the gateway error.

The nginx.conf file is:

#user nginx;  
worker\_processes 1;

#error\_log /var/log/nginx/error.log;  
#error\_log /var/log/nginx/error.log notice;  
#error\_log /var/log/nginx/error.log info;

#pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
#log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request”  
’  
# '$status $body\_bytes\_sent “$http\_referer” ’  
# ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;  
“nginx.conf” 40L, 847C

Posted at Nginx Forum:

> **[Re: connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233527#msg-233527)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 10:54pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/7 "2012-12-03T22:54:31Z")

</div>

On Tuesday 04 December 2012 01:32:04 Gallitin wrote:

> Sorry for the grammar error.
> 
> If I do curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)  
> it returns the code from the msgFBmodal.js page. Yet if I hit the page via  
> browser I still receive the gateway error.  
> […]

You should clear your browser’s cache.

wbr, Valentin V. Bartenev

–

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 10:57pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/8 "2012-12-03T22:57:27Z")

</div>

Just tried that still receiving the error

Posted at Nginx Forum:

> **[Re: connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233530#msg-233530)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 9:29pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/9 "2012-12-03T21:29:49Z")

</div>

Via SSH? Yes I can do this.

When I do that it says

HTTP/1.1 404 Not Found  
Date: Mon, 03 Dec 2012 20:28:35 GMT  
Server: Apache  
Content-Length: 286  
Connection: close  
Content-Type: text/html; charset=iso-8859-1

404 Not Found
# Not Found

The requested URL /assets/js/msgFBmodal.js was not found on this server.

* * *
Apache Server at 108.166.94.94 Port 7080

No if I do:  
curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)

It returns the page code from that file.

Posted at Nginx Forum:

> **[Re: connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233524#msg-233524)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 11:03pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/10 "2012-12-03T23:03:53Z")

</div>

I run the curl command via SSH and I receive the code output from that  
file.

I browse to the page that uses that file and receive the gateway error.

Posted at Nginx Forum:

> **[Re: connect() failed (111: Connection refused) while connecting to upstream](https://forum.nginx.org/read.php?2,233519,233532#msg-233532)**
>
> Can't figure out why I keep getting 502 bad gateway nginx error. Here is the error from nginx error log. 2012/12/03 19:30:21 \[error\] 20650#0: \*939328 connect() failed (111: Connection refused) while connecting to upstream, client: 70.94.18.35,...

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 11:00pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/11 "2012-12-03T23:00:22Z")

</div>

On 3 December 2012 21:56, Gallitin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just tried that still receiving the error

So a curl _running_on_your_desktop\* receives a 200 as expected, but  
your browser _on_your_desktop_ does not?

Jonathan

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 3, 2012, 11:20pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/12 "2012-12-03T23:20:14Z")

</div>

On 3 December 2012 22:03, Gallitin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I run the curl command via SSH and I receive the code output from that  
> file.
> 
> I browse to the page that uses that file and receive the gateway error.

You need to show us some commands running, some output, and nginx  
config - without redacted network names. This is too  
annoying/confusing to help you troubleshoot without seeing exactly  
what you’re running exactly where.

Jonathan

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [March 11, 2017, 3:35pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/13 "2017-03-11T15:35:05Z")

</div>

Gallitin wrote in post #1087697:

> Can’t figure out why I keep getting 502 bad gateway nginx error. Here is  
> the  
> error from nginx error log.
> 
> 2012/12/03 19:30:21 [error] 20650#0: \*939328 connect() failed (111:  
> Connection refused) while connecting to upstream, client: 70.94.18.35,  
> server: [demo.domain.com](http://demo.domain.com), request: “GET /assets/js/msgFBmodal.js  
> HTTP/1.1”,  
> upstream: “[http://108.166.94.94:7080/assets/js/msgFBmodal.js](http://108.166.94.94:7080/assets/js/msgFBmodal.js)”, host:  
> “[demo.domain.com](http://demo.domain.com)”, referrer:  
> “[http://demo.domain.com/register/user\_profile](http://demo.domain.com/register/user_profile)”
> 
> I’m on a rackspace cloud sever, centos.
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,233519,233519#msg-233519](http://forum.nginx.org/read.php?2,233519,233519#msg-233519)

Did you got solution to the problem ? I’m getting error  
connect() failed (111: Connection refused) while connecting to upstream

You check more details upon opening site [http://www.dealslama.com](http://www.dealslama.com)

An error occurred.

Sorry, the page you are looking for is currently unavailable.  
Please try again later.

If you are the system administrator of this resource then you should  
check the error log for details.

Faithfully yours, nginx.

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [December 4, 2012, 12:58am UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/14 "2012-12-04T00:58:59Z")

</div>

On Mon, Dec 03, 2012 at 04:32:04PM -0500, Gallitin wrote:

Hi there,

> Sorry for the grammar error.

No worries. Once it is clear what works and what fails, we can see what  
to do next.

> If I do curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)  
> it returns the code from the msgFBmodal.js page. Yet if I hit the page via  
> browser I still receive the gateway error.

So, include all details each time, even if it looks repetitive.

Yes or no: “[domain.com](http://domain.com)” is your nginx-hosted web site, and resolves to  
your nginx server?

From a shell on the nginx server, what does

curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)

return? HTTP 200 and the content of the msgFBmodal.js file, or something  
else?

From a shell on your PC, the same machine your browser runs from, what  
does

curl -i [http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)

return? HTTP 200 and the content of the msgFBmodal.js file, or something  
else?

From your browser, what do you see when you try to access

[http://domain.com/assets/js/msgFBmodal.js](http://domain.com/assets/js/msgFBmodal.js)

? The content of the msgFBmodal.js file, or something else?

> The nginx.conf file is:

> ```
> # '$status $body_bytes_sent "$http_referer" '
> # '"$http_user_agent" "$http_x_forwarded_for"';
> 
> ```
> 
> “nginx.conf” 40L, 847C

Unfortunately, that doesn’t show the configuration. It only shows the  
top  
half of the main file; I suspect it will “include” some other files.  
What  
matters is the configuration of the server{} block that handles  
[domain.com](http://domain.com).

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Gallitin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gallitin](https://www.ruby-forum.com/u/Gallitin)\
**Post date:** [March 11, 2017, 3:36pm UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/15 "2017-03-11T15:36:22Z")

</div>

connect() failed (111: Connection refused) while connecting to upstream

My site : [http://www.dealslama.com](http://www.dealslama.com) showing below error message.

An error occurred.

Sorry, the page you are looking for is currently unavailable.  
Please try again later.

If you are the system administrator of this resource then you should  
check the error log for details.

Faithfully yours, nginx.

---

<div class="post-metadata">

**Author:** ![sourabhjain01](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/sourabhjain01/32/1239_2.png) [@sourabhjain01](https://www.ruby-forum.com/u/sourabhjain01)\
**Post date:** [November 12, 2019, 7:25am UTC](https://www.ruby-forum.com/t/connect-failed-111-connection-refused-while-connecting-to-upstream/224936/16 "2019-11-12T07:25:13Z")

</div>

Well, due to occurring such problems of not getting the confirmation. you may use such services as [SMPP Server](http://smpp.in), SMPP.
