0

End goal: I am attempting to fetch the Ruby on Rails port

I am using nginx as a load-balancer, to juggle between several different ruby on rails servers that I have running using thin.

I followed this tutorial to figure out how to proxy_pass to the different servers, but I want to see if it is indeed working. The only way I can figure out if this is working, is to see the port that the thin server is running on.

I am unable to use request.port as the request is actually routed through nginx, therefore every request port has 80. When I need the port that the rails server is truly running on.

Per this answer, I've tried using:

Rails::Server.new.options[:Port]

Which works just fine in Development mode, but when switching to production mode, it gives me a 500 saying

FATAL -- : ActionView::Template::Error (uninitialized constant Rails::Server)

nginx config

server_name myname.com;

upstream dashboard_servers {
  server <hidden>:3001 fail_timeout=0;
  server <hidden>:3002 fail_timeout=0;
  server <hidden>:3003 fail_timeout=0;
  server <hidden>:3004 fail_timeout=0;
}

server {
  listen 3000;

  location / {
    # set proxy headers
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://dashboard_servers;
  }
}

my rails servers are on ports 3001-3004 and this is the port i need.

How can I get the port that the Rails server is truly running on?

Community
  • 1
  • 1
ddavison
  • 28,221
  • 15
  • 85
  • 110

1 Answers1

0

Well if you're trying to run that command in rails console, I think that's why it's giving you that error, because there's no port, I just tested this locally by adding that line in my layout and it worked fine

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89