单个服务器上的多个Rails应用程序(2个独立的域)-PUMA和Nginx

时间:2019-02-06 16:10:17

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

我检查了很多stackoverflow,但是需要对如何做到这一点有一个正确的答案。

我有2台配置了nginx,puma和capistrano的(ubuntu)服务器,分别为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应用程序(单独的域)。

1 个答案:

答案 0 :(得分:0)

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

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

对此ssl进行相同的操作。