【问题标题】:multiple rails app (2 separate domains) on a single server - puma and nginx单个服务器上的多个 Rails 应用程序(2 个单独的域) - puma 和 nginx
【发布时间】:2019-06-30 15:47:37
【问题描述】:

我已经检查了许多 stackoverflow,但需要有一个正确的答案来说明如何做到这一点。

我有 2 个(ubuntu)服务器,它们配置了 nginx、puma 和 capistrano,以服务于各自的 rails 应用程序。 为了节省成本,我希望它只托管在一台服务器上。

这里有一些链接,但不清楚需要做什么:

Setting up multiple rails apps using nginx and Puma is it possible to have multiple project of rails on same port?

我的服务器 nginx.conf(用于第一个应用程序):

upstream pumawebapp {
  server unix:///home/user1/apps/webapp/shared/tmp/sockets/webapp-puma.sock;
}

server {
  listen 80;
  server_name webapp.org www.webapp.org;
  return 301 https://webapp.org$request_uri;
}


server {
  listen 443;
  server_name webapp.org;

  ssl on;
  ssl_certificate /etc/ssl/webapp_bundle.crt;
  ssl_certificate_key /etc/ssl/webappserver.key;


  root /home/user1/apps/webapp/current/public;
  access_log /home/user1/apps/webapp/current/log/nginx.https.access.log;
  error_log /home/user1/apps/webapp/current/log/nginx.https.error.log info;

location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @pumawebapp;
  location @pumawebapp {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://pumawebapp;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

我需要了解如何能够在我拥有的当前 puma + nginx 环境中的服务器中托管 2 个 rails 应用程序(单独的域)。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 nginx puma


    【解决方案1】:

    您只需要使用另一个 server_name 创建另一个 nginx 服务器

    server {
      listen 80;
      server_name webapp2.org www.webapp2.org;
      return 301 https://webapp2.org$request_uri;
    }
    

    对这个新服务器的 ssl 执行相同的操作。

    【讨论】:

    • 这么简单,puma 怎么样,有什么应该做的吗?
    • 这个怎么样?上游 pumawebapp
    • 和这个位置 ^~ /assets/
    • 您也可以创建 2 个上游应用。每个上游应该通过proxy_pass属性属于1个nginx服务器。
    • 至于/assets/,我们的ssl配置中包含它,所以我们可以在新的nginx服务器配置中复制它。
    猜你喜欢
    • 2014-11-06
    • 2011-09-24
    • 2011-02-23
    • 1970-01-01
    • 2014-05-06
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    相关资源
    最近更新 更多