1
votes

I have checked many stackoverflow but there needs to be a proper answer on how to do this.

I have 2 (ubuntu) servers that is configured with nginx, puma and capistrano to serve respective rails app. To save cost, I want to have to have it hosted on just one server.

Here are some links but its not clear what needs to be done:

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

my server nginx.conf (for the first app):

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;
}

I need to find out how to be able to host 2 rails apps (separate domains) in a server in the current puma + nginx environment that I have.

1

1 Answers

0
votes

You just need to create another nginx server with another server_name

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

Do the same with ssl for this new server.