2017-06-15 68 views
0

不好意思问候noob问题。无法使用我的Ubuntu服务器的公网IP在浏览器中访问我的Rails应用程序

我有一个Ubuntu 16.04.1 LTS(GNU/Linux 4.4.0-63-generic x86_64)服务器,我的公有IP是类似于183.xx.xxx.xx(curl -4 icanhazip.com).I

rails s -b0.0.0.0 -p3002 

和彪马服务器已成功启动

=> Booting Puma 
    => Rails 5.0.3 application starting in development on http://localhost:3002 
    => Run `rails server -h` for more startup options 
    Puma starting in single mode... 
    * Version 3.9.1 (ruby 2.4.0-p0), codename: Private Caller 
    * Min threads: 5, max threads: 5 
    * Environment: development 
    * Listening on tcp://0.0.0.0:3002 
    Use Ctrl-C to stop 

我试图访问我的应用程序在浏览器中使用:使用命令运行我的Rails应用程序

http://183.xx.xxx.xx:3002 

我越来越

This site can’t be reached 
172.xx.xxx.xx took too long to respond. 
ERR_CONNECTION_TIMED_OUT  

netstat的-plnt

tcp  0  0 0.0.0.0:45109   0.0.0.0:*    LISTEN  - 
    tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN  - 
    tcp  0  0 127.0.0.1:631   0.0.0.0:*    LISTEN  - 
    tcp  0  0 127.0.0.1:5432   0.0.0.0:*    LISTEN  - 
    tcp  0  0 0.0.0.0:3002   0.0.0.0:*    LISTEN  25689/0.0.0.0:3002) 
    tcp  0  0 127.0.0.1:6010   0.0.0.0:*    LISTEN  - 

的处理与PID 25689

任何帮助运行事先高度Appreciate.Thanks!

+0

您一定要使用正确的IP验证'ifconfig' –

+0

你为什么想要通过端口访问您的导轨应用程序?只需使用Web服务器进行配置即可。比如:apache2或Nginx – hgsongra

+0

@ Farhan,谢谢你的回复。我确定使用正确的公有IP。 – suresh

回答

0
rails s -b 192.168.1.23 -p 3000 

然后 运行

192.168.1.23:3000 
+0

@Dhanesh,谢谢你的回答。按照你的建议,我试过用rails s -b 183.xx.xxx.xx -p3002,但是我得到了(Errno :: EADDRNOTAVAIL)。 – suresh

0

您应该编辑您的/etc/hosts文件0.0.0.0点到你的公网IP(183.xx.xxx.xx)

测试:

#/etc/hosts 
127.0.0.1 localhost 
127.0.1.1 pavan 
0.0.0.0  192.xxx.x.xxx #my ip 

现在我跑到铁轨服务器rails s -b 0.0.0.0 -p 3002,我可以用我的IP (192.xxx.x.xxx:3002)

+0

感谢您的快速响应。我在/ etc/hosts文件中添加了0.0.0.0 183.xx.xxx.xx,但仍然无法访问我的浏览器中的应用程序。我的代码位于/ var/www文件夹中183.xx.xxx.xx服务器。 – suresh

0

访问有关的公共IP启动您的服务器首先,你需要找到朝外你的公网IP,可以通过运行命令Ubuntu的终端ifconfig

复制下的eth0重点提到的IP上进行:

eth0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX inet addr:192.168.X.XXX

有关此公网IP启动您的轨道服务器必须运行命令:

rails s -b PUBLIC_IP_OF_SYSTEM -p PORT_TO_BOOT_ON 

在你的情况会是这样:

rails s -b 183.xx.xxx.xx -p 3002 
相关问题