ruby-on-rails - 如何使用 nginx 在 EC2 上运行两个应用程序

标签 ruby-on-rails regex nginx amazon-ec2 production-environment

我是 Ubuntu 的新手,通常是服务器端,我创建了一个 Rails 应用程序并将其部署在 Ubuntu Ec2 上。 我正在其上使用 Nginx 和 Thin 服务器。该应用程序在其上完美运行。

现在我想在同一服务器上部署另一个应用程序。 我已经将应用程序放在服务器上,当我尝试启动 Rails 应用程序时,它没有启动。 我猜是因为 nginx.conf 文件。

有人可以告诉我如何在同一服务器上运行两个应用程序

最佳答案

当您尝试浏览 Amazon EC2 上的计算机并且没有收到任何响应时,最好的怀疑是 AWS Security Group 。确保应用程序运行的端口在您计算机的安全组中打开:

Security group screen
(来源:amazon.com)

要让 nginx 运行这两个应用程序,您需要在其 nginx.conf 上配置它们

upstream app1 {
  server 127.0.0.1:3000;
}

upstream app2 {
  server 127.0.0.1:3020;
}
server {
  listen   80;
  server_name .example.com;

  access_log /var/www/myapp.example.com/log/access.log;
  error_log  /var/www/myapp.example.com/log/error.log;
  root     /var/www/myapp.example.com;
  index    index.html;

  location /app1 {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    proxy_redirect  off;
    proxy_pass http://app1;
  }

  location /app2 {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    proxy_redirect  off;
    proxy_pass http://app2;
  }
}

此配置将监听本地端口 3000 上的 app1 和本地端口 3020 上的 app2,并重定向以 http://my.example 开头的数据.com/app1 到第一个应用,以 http://my.example.com/app2 开头的数据到第二个应用。

关于ruby-on-rails - 如何使用 nginx 在 EC2 上运行两个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22064397/

相关文章:

Django send_mail() 在 shell 中工作,但不在 nginx 生产中工作

ruby-on-rails - Rails 查找 - 按回形针附件的存在进行排序,然后记录创建日期时间

java - java中日期的正则表达式

c++ - 用于格式化 MAC 地址字符串的 Boost Regex

nginx - 通过 http 进行 RTMP 流式传输

caching - 当接近磁盘限制时,Nginx 缓存管理器会清除文件吗?

javascript - 如何使用 link_to :remote => true 跟踪 ajax 调用

ruby-on-rails - 如何在 Ruby 中将 JSON 对象附加在一起

ruby-on-rails - 如何在 Rails 3 中获取资源的绝对路径?

regex - RewriteCond 无法对 HTTP_HOST 强制使用 https