【问题标题】:Starting a rails app to the external ip address启动 Rails 应用程序到外部 IP 地址
【发布时间】:2016-05-08 03:16:57
【问题描述】:

我有一个 ruby​​ on rails 应用程序,我正在尝试在我的 google 计算引擎 ubuntu 14.04 LTS VM 的外部 IP 上运行它。

我试试rails server -e production

输出是:

=> Booting Puma
=> Rails 4.2.4 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.14.0 starting...
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://localhost:3000

我不希望它在那个位置;我希望它可以从服务器的外部 IP 地址查看。

部分问题是我不知道这是一个 rails、puma 还是 google 计算引擎问题。

注意:我看不到它是否真的在 localhost:3000 启动,因为 VM 只是一个终端。

【问题讨论】:

  • 因此,在这种情况下,localhost 将代表您的 IP(除非您有更复杂的设置);将其绑定到特定 IP:rails s -b 0.0.0.0;您可能会发现使用Passenger 更友好。此外,请查看 DigitalOcean 的在其服务器上运行 rails 应用程序的指南。他们有很好的文章,而且与提供者无关。
  • @JoshBrody 所以,如果它将它返回到命令行,那么它应该可以在外部查看,除非有一些本地代码阻止它?
  • 理论上,是的。它可能是防火墙(可能是 iptables)。就可公开访问而言,本地和产品设置几乎没有什么区别。为确保一切正常,您可能需要gem install localtunnel 并运行它,以确保这不是一些奇怪的防火墙问题。
  • 您可能还需要配置虚拟机的网络设置。例如。对于 kvm 或 VirtualBox,如果不进行一些配置,它将无法工作。

标签: ruby-on-rails google-compute-engine puma


【解决方案1】:

(我假设你使用的是nginx,如果没有,apt-get install nginx; service nginx start) 如果可能,请显示您的 nginx.conf (/etc/nginx/nginx.conf) 和 default.conf (/etc/nginx/sites-available/default.conf) 由于您使用的是 puma(我也使用它),因此您应该设置 nginx conf 文件并将服务器上游设置为等于 puma 的绑定。

# /etc/nginx/sites-available/default.conf
upstream your_app {
     server 127.0.0.0.1:9292;
}

server {
     listen 80;
     server_name your_domain;
     root /usr/share/nginx/your_app/public;
     # or, if you are using capistrano
     root /usr/share/nginx/your_app/current/public;

     location / {
          proxy_pass http://your_app; # equal to upstream "name"
         ...
     }
     ....
 }

 # config/puma.rb
 [...]
 bind "tcp://127.0.0.1:9292"

并执行puma的服务器

$ bundle exec puma RAILS_ENV=production &

执行此步骤后,如果应用程序仍然无法运行,请输出您的 /var/log/nginx/error.log、nginx.conf 和 default.conf

【讨论】:

  • 如果我没有域名,目前只使用ip,your_domain应该是什么?
  • 我也找不到我的 config/puma.rb 文件,我找不到任何名为 puma.rb 的文件。另外,我刚刚注意到这是我 3 天前的问题,我今天在这里又问了一遍:stackoverflow.com/questions/35152369/…
猜你喜欢
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
  • 2017-01-20
  • 2011-08-03
  • 2021-07-06
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多