Home > other >  rails server running in production model but can not access from internet
rails server running in production model but can not access from internet

Time:10-16

I recently updated ruby to 2.6.10 (from 2.1.0), and rails to 4.2.8 (from 4.1.8) after starting the server in production mode

sudo RAILS_ENV=production /home/ubuntu/.rbenv/shims/rails s -p 80
=> Booting WEBrick
=> Rails 4.2.8 application starting in production on http://localhost:80
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2022-10-09 13:39:04] INFO  WEBrick 1.4.4
[2022-10-09 13:39:04] INFO  ruby 2.6.10 (2022-04-12) [x86_64-linux]
[2022-10-09 13:39:04] INFO  WEBrick::HTTPServer#start: pid=25476 port=80

It didn't complain anything, but type in http://xx.xx.xx.xx:80/main/home in public chrome browser shows "this site cannot be reached"

running sudo lsof -i -P -n | grep LISTEN shows

privoxy   24676    privoxy    4u  IPv4 308828941      0t0  TCP 127.0.0.1:8118 (LISTEN)
privoxy   24676    privoxy    5u  IPv4 308828942      0t0  TCP 127.0.0.2:8118 (LISTEN)
ruby      25476       root    7u  IPv4 308931749      0t0  TCP 127.0.0.1:80 (LISTEN)
mongod    26844    mongodb    8u  IPv4 167571089      0t0  TCP 127.0.0.1:27017 (LISTEN)
tor       27283 debian-tor    7u  IPv4 167571327      0t0  TCP 127.0.0.1:9050 (LISTEN)
sshd      28852       root    3u  IPv4 167571990      0t0  TCP *:22 (LISTEN)
sshd      28852       root    4u  IPv6 167571992      0t0  TCP *:22 (LISTEN)

How to check what is going on?

CodePudding user response:

After some trials and error, I noticed rails 4.2.8 does not default to listening 0.0.0.0 (while 4.1.8 does)

so in order to listen publicly, I need to run

sudo RAILS_ENV=production /home/ubuntu/.rbenv/shims/rails s -b0.0.0.0 -p 80

or add the following to boot.rb

require 'rails/commands/server'

module Rails
  class Server
    alias :default_options_bk :default_options
    def default_options
      default_options_bk.merge!(Host: '0.0.0.0')
    end
  end
end
  • Related