레일즈 웹서버 외부 접속 허용하기

(레일즈 서버 외부 접속 허용하기에서 넘어옴)
레일즈 서버 외부 접속 허용하기

1 확인[ | ]

railsuser@zetawiki:~/my_app$ netstat -tnlp | grep ruby
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      27530/ruby      
tcp6       0      0 ::1:3000                :::*                    LISTEN      27530/ruby
→ 로컬호스트에서만 접속 가능하게 되어 있음

2 방법 1: 임시 적용[ | ]

  • 서버 중지하고 전체 IP(0.0.0.0) 허용하여 서버 시작
railsuser@zetawiki:~/my_app$ kill -9 `pidof ruby`
railsuser@zetawiki:~/my_app$ rails server -d -b 0.0.0.0
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
railsuser@zetawiki:~/my_app$ netstat -tnlp | grep ruby
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      27628/ruby
→ 모든 IP에 대해 LISTEN

3 방법 2: 영구 적용[ | ]

railsuser@zetawiki:~/my_app$ vi bin/rails
#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'

# Webrick listen on all IPs
require 'rails/commands/server'

module Rails
  class Server
    def default_options
      super.merge({
      	:Host		 => '0.0.0.0',
        :Port        => 3000,
        :environment => (ENV['RAILS_ENV'] || 'development').dup,
        :daemonize   => false,
        :debugger    => false,
        :pid         => File.expand_path('tmp/pids/server.pid'),
        :config      => File.expand_path('config.ru')
      })
    end
  end
end

require 'rails/commands'
  • 서버 재시작
railsuser@zetawiki:~/my_app$ kill -9 `pidof ruby`
railsuser@zetawiki:~/my_app$ rails server -d
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
railsuser@zetawiki:~/my_app$ netstat -tnlp | grep ruby
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      28605/ruby
→ 모든 IP에 대해 LISTEN

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}