Home  >  Q&A  >  body text

ruby - rails 生成的项目开启服务后,为什么 “无法访问”

我时个新手……折腾好几天了 TAT
现在用的是最新的rails,今天在linux (centos6.4) 安装好ruby,rails后新建的项目,启动 rails server后如下提示

=> Booting WEBrick
=> Rails 4.1.6 application starting in development on http://0.0.0.0:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
[2014-10-01 15:51:07] INFO WEBrick 1.3.1
[2014-10-01 15:51:07] INFO ruby 2.1.3 (2014-09-19) [i686-linux]
[2014-10-01 15:51:07] INFO WEBrick::HTTPServer#start: pid=30770 port=3000

但是我在浏览器访问 http://linux服务器IP:3000 确是无法访问……(因为不是本机当然不能用 127.0.0.1 去访问咯,即使有-b linux服务器IP 来开启服务,也是无法访问

PHPzPHPz2712 days ago1056

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-22 09:01:10

    1. This "Linux server" is a 真实的网络另一端的服务器,还是你本地的virtual machine?

    2. If it is a real server, it is recommended to check the firewall. If it is a virtual machine, it is recommended to configure the virtual machine and use 端口转发,例如把虚拟机的3000端口转发到母机器4000端口 so that you can access the project through 127.0.0.1:4000 on the parent machine.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-22 09:01:10

    The output looks normal. Listening to 0.0.0.0 allows everyone to access it. If it still doesn’t work, check the firewall

    Try turning off the firewall

    reply
    0
  • 迷茫

    迷茫2017-04-22 09:01:10

    Solve the problem that external browsers cannot access the rails environment configured in the virtual machine on the virtual machine:
    Use rails s -b192.168.xx.xx
    After -b is the IP that needs to be monitored, which is the IP address of the server, and then you can access it
    Because if you open the service directly according to rails s, what is monitored is http://localhost:3000, or 127.0.0.1
    So you need to change the monitoring IP. Of course, you can also change the monitoring port and add -pxxxx

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-22 09:01:10

    Solved it

    rvmsudo rails s -b 0.0.0.0 -p 80
    where 0.0.0.0 is the allowed IP
    80 is the port

    Good luck

    reply
    0
  • Cancelreply