如何使我的ruby on rails应用程序响应外部请求(在Internet上对公众可见)? [英] How do I make my ruby on rails app respond to external requests (visible to the public on the internet)?

查看:116
本文介绍了如何使我的ruby on rails应用程序响应外部请求(在Internet上对公众可见)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: 我的Rails应用程序(在我的本地机器上)仅响应从同一台机器发送到本地主机,127.0.0.1或我的内部IP地址的请求.当我尝试使用Internet ip或网络内部或外部的任何其他计算机访问它时,它只是超时.我使用的是Mac OS 10.9.1,ruby 1.9.3,rails 4.0.0.

Problem: My rails app (on my local machine) only responds to requests sent from the same machine to localhost, 127.0.0.1, or my internal ip address. When I try to hit it using my internet ip or from any other machine, inside or outside of my network, it just times out. I'm on Mac OS 10.9.1, ruby 1.9.3, rails 4.0.0.

我已经做了很多搜索,但是我发现的问题是人们没有转发其端口或绑定正确的ip.

I've done a lot of searching but all I can find is problems where people didn't forward their ports or bind the right ip.

这是我调查过的领域:

端口- 我尝试了几个不同的端口.我将路由器配置为转发尝试的每个端口,但结果相同.我以为路由器可能有问题,所以我用Java构建了一个简单的服务器,并绑定了与Rails应用程序绑定的所有相同端口.果然,当我使用Internet ip访问Java应用程序时,它运行良好,因此路由器/防火墙/端口转发不是问题.另外,我在端口80上运行了一个apache服务器,它从来没有任何问题.我关闭了Apache并尝试将80端口用于我的Rails应用程序,但这并不能解决问题.

Ports - I've tried several different ports. I configured my router to forward every port I tried but got the same result. I thought maybe there was a problem with the router so I built a simple server in Java and bound all the same ports I was binding with my rails app. Sure enough, when I hit the Java app using my internet ip it worked just fine so the router/firewall/port forwarding isn't the problem. Also, I run an apache server on port 80 and that has never had any problems. I turned apache off and tried port 80 for my rails app but that didn't fix the problem.

Rails服务器- 我从WEBrick开始,我认为内部可能存在某些设置阻止了外部请求.我在google上进行了广泛搜索,但没有发现任何问题.为了安全起见,我安装了Thin并获得了与WEBrick完全相同的结果.一件有趣的事情是,当启动Rails服务器时,外部请求需要很长时间才能超时,但是服务器控制台根本不显示任何输出.但是,如果我尝试发送相同的请求而没有启动服务器,那么它将立即失败.

Rails Server - I started with WEBrick and I thought that perhaps there was some setting inside that blocked external requests. I searched google extensively and found nothing on that matter. Just to be safe I installed Thin and got the exact same result I did with WEBrick. One interesting thing is that when the rails server is started, the external request takes a long time to time-out, but the server console displays no output at all. However if I try to send the same request w/out starting the server at all it fails immediately.

用户权限- 我用root启动服务器(我开始在这里只是在黑暗中拍摄),它没有任何作用.

User Permissions - I started the server with root (i'm starting to just shoot in the dark here) and it had no effect.

环境- 我最初是在开发环境中开始的,因为我正在开发,但只是出于娱乐目的,我尝试从生产中开始,这也没有任何区别.

Environment - I was starting in development environment originally because I'm developing but just for fun I tried starting in production and it also made no difference.

请帮助我聪明的人

更新: 我在Ubuntu机器上安装了该应用程序,它没有这个问题!因此,这表明该问题可能与Mac OS有关.

Update: I installed the app on my Ubuntu machine and it doesn't have this problem! So that suggests the problem may have something to do with Mac OS.

已解决: 事实证明,在系统偏好设置->安全性和隐私-> Mac OS中的防火墙,它以某种方式设置为阻止与Ruby 1.9.3的传入连接.我一定是在一段时间前不小心设置了.

SOLVED: It turns out that in the System Preferences -> Security & Privacy -> Firewall in Mac OS, it was somehow set to block incoming connections to Ruby 1.9.3. I must have accidentally set that some time ago.

推荐答案

问题是您可能正在尝试从本地计算机(或防火墙后的本地网络中的任何计算机)向您的公共IP请求页面结果...除非您为此设置通过防火墙的路由(通常在消费者级别的路由器上不可用... linksys,dlink等)

The problem is you are probably trying to request the page from your local machine (or any computer on your local network, behind your firewall) to your public IP expecting a result... not unless you setup routes through your firewall for this (and not usually available on a consumer level router... linksys, dlink, etc)

因此,如果您使用的是pow之类的端口,则将端口80转发,或者将3000作为Web Bricks的默认端口转发至本地计算机

So forward port 80 if you are using something like pow, or 3000 for web bricks default port to your local machine

然后在您本地局域网之外的某人请求您的外部(公共)IP

Then have someone outside your local lan request your external (public) IP

这篇关于如何使我的ruby on rails应用程序响应外部请求(在Internet上对公众可见)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆