Connect () failed (111: connection refused) when connecting to upstream

I host my Rails application on Rackspace with the nginx web server.

When calling any Rails API, I see this message in /var/log/nginx/error.log: * 49 connect () failed (111: connection refused) when connecting to the upstream, client: 10.189.254.5, server :, request : "POST / api / v1 / users / sign_in HTTP / 1.1", upstream: " http://127.0.0.1 {001/api/v1/users/sign_in", host: "anthemapp.com"

  • What is an upstream block?
  • What is / etc / nginx / sites -available / default? Is this where I can configure this?
  • Why am I getting the error above?

I spent several hours with 5-6 different Rackspace technicians (they did not know how to resolve this). It all started when I turned on the server in rescue mode and completed the following steps: https://community.rackspace.com/products/f/25/t/69 . As soon as I left rescue mode and rebooted the server, I started getting the error that I am writing about. Tnx!

+6
source share
3 answers

Nginx is a reverse proxy server - its role on your server is to accept HTTP requests and pass them to another process on the same host. The "upstream" referred to in the error message refers to a bit in the nginx configuration (of which the /etc/nginx/sites-available/default file is part), which tells it where to send incoming requests. The error message you see indicates that nginx received the request, but was unable to send it to another process that it should have used.

When your server rebooted, the nginx process started, but your Rails process β€” the one intended for listening on port 3001 β€” did not!

How to restart the Rails process depends on how you started it before and how your server is configured. It can be as simple as cd entering your Rails application directory on the server and running:

 rails server -b 127.0.0.1 -p 3001 -e production -d 

... but to prevent similar situations in the future (and to improve the performance of your Rails application!) it would be better to use some kind of Rails application server ready for production. I would recommend using Phusion Passenger , because this is the most suitable solution - they are described for installation and configuration for nginx , but there are many alternatives. There's an excellent record of what your options are, what they all mean, and how they relate to fooobar.com/questions/13951 / ....

+9
source

In my case, I need to run:

 bundle install bundle update 

and then:

 sudo stop puma-manager sudo start puma-manager 
0
source

This is allowed when I run the command.

 cap production puma:restart 

Sometimes this happens if we switch the ruby ​​version to production

0
source

Source: https://habr.com/ru/post/981949/


All Articles