2017-06-15 71 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 
相關問題