multiple rails apps on nginx and unicorn

后端 未结 3 905
北荒
北荒 2020-12-07 23:32

I successfully setup a rails site using the Screencast 335 deploy to a VPS tutorial. Now I want to add another rails app on a new domain but I am confused about the steps re

3条回答
  •  庸人自扰
    2020-12-08 00:31

    In unicorn.rb:

    application 1:

    root = "/var/www/application_1/current"
    working_directory root
    pid "#{root}/tmp/pids/unicorn-app1.pid"
    listen "/tmp/unicorn.app1.sock"
    

    application 2:

    root = "/var/www/application_2/current"
    working_directory root
    pid "#{root}/tmp/pids/unicorn-app2.pid"
    listen "/tmp/unicorn.app2.sock"
    

    In nginx.conf:

    application 1:

    upstream app1_server {
      server unix:/tmp/unicorn.app1.sock fail_timeout=0;
    }
    
    server {
      listen 80;
      server_name my_app_1.com www.my_app_1.com;
      root /var/www/app1/current/public;
    
      location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
      }
    
      try_files $uri/index.html $uri @app1_server;
      location @app1_server {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app1_server;
     }
    
      error_page 500 502 503 504 /500.html;
      client_max_body_size 4G;
      keepalive_timeout 10;
    }
    

    application 2:

    upstream app2_server {
      # point to app2 sock
      server unix:/tmp/unicorn.app2.sock fail_timeout=0;
    }
    
    server {
      listen 80;
      server_name my_app_2.com www.my_app_2.com;
      root /var/www/app2/current/public;
    
      location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
      }
    
      try_files $uri/index.html $uri @app2_server;
      location @app2_server {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app2_server;
     }
    
      error_page 500 502 503 504 /500.html;
      client_max_body_size 4G;
      keepalive_timeout 10;
    }
    

提交回复
热议问题