Question

Can NOT run rails application on my server's IP address only runs at localhost:3000

Posted July 28, 2017 13.2k views
Ruby on RailsNginxRubyUbuntu 16.04

I deployed my rails application on the server with capistrano, nginx and puma, following this tutorial-
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma.

App is running fine in localhost:3000.
I can also run on-> rails server –binding=MyIP
I can see my app in action on-> http://My
IP:3000

When I browse http://My_IP , I saw welcome to nginx screen.
But according to document, when I run -
sudo rm /etc/nginx/sites-enabled/default
sudo ln -nfs “/home/username/apps/appname/current/config/nginx.conf” “/etc/nginx/sites-enabled/appname”
(Ofcourse I changed username and appname)

I can NOT connect to my server’s IP address (says Unable to connect.. can’t establish a connection).

Nginx server is running. I also tried running with systemctl start nginx command.

May be something wrong with Puma? I can NOT connect my Puma web server to the Nginx reverse proxy? I am not sure.

I searched online, some people have puma.rb file but I don’t have(document does not mention). I just have Puma gem in my Gemfile. Do I need config/puma.rb file?

I have-
Rails -v 4.2.5
Ruby -v 2.3.0

So my problem is I can NOT run my application on my servers IP address. App is only running default on localhost:3000
Is it problem with port 80? Puma is not connected to port 80?

I need help running my application in production.

Thank you.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi @vishdev

Without seeing the content of the Nginx site configuration that you link to, then it’s difficult to know what’s going on. So post this file:

/home/username/apps/appname/current/config/nginx.conf

And also post the last 10 lines from your Nginx error log:

tail -10 /var/log/nginx/error.log

Hi Hansen,
Thank you for your reply.
Here is my nginx.conf file-

upstream puma {
  server unix:///home/vish/apps/globe3/shared/tmp/sockets/globe3-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/vish/apps/globe3/current/public;
  access_log /home/vish/apps/globe3/current/log/nginx.access.log;
  error_log /home/vish/apps/globe3/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

sudo tail -10 /var/log/nginx/error.log

2017/07/28 06:48:14 [crit] 14839#14839: *33 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 138.68.229.14, server: localhost, request: "GET /nginx_status HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/500.html", host: "138.68.229.14"
2017/07/28 06:48:40 [notice] 14879#14879: signal process started
2017/07/28 06:48:56 [crit] 14904#14904: *1 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/", host: "138.68.229.14"
2017/07/28 06:48:56 [crit] 14904#14904: *1 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/500.html", host: "138.68.229.14"
2017/07/28 06:48:57 [crit] 14904#14904: *1 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/", host: "138.68.229.14"
2017/07/28 06:48:57 [crit] 14904#14904: *1 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/500.html", host: "138.68.229.14"
2017/07/28 07:13:46 [crit] 14904#14904: *6 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/", host: "138.68.229.14"
2017/07/28 07:13:46 [crit] 14904#14904: *6 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/500.html", host: "138.68.229.14"
2017/07/28 07:13:48 [crit] 14904#14904: *6 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/", host: "138.68.229.14"
2017/07/28 07:13:48 [crit] 14904#14904: *6 connect() to unix:/home/vish/globe3/shared/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 24.6.255.25, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/vish/globe3/shared/sockets/puma.sock:/500.html", host: "138.68.229.14"
  • @vishdev

    Okay, in the Nginx configuration change this:

      listen 80 default_server deferred;
      # server_name example.com;
    

    To this to make that site available on anything (your IP, a domain):

      listen 80 default_server;
      server_name _;
    

    Then you need to make sure that Puma is running and using the same socket as you have defined in Nginx:

    /home/vish/apps/globe3/shared/tmp/sockets/globe3-puma.sock
    

    And then test your Nginx configuration and restart it:

    sudo service nginx configtest
    sudo service nginx restart
    
Submit an Answer