将多个Rails应用程序部署到DigitalOcean

mar*_*dze 6 sockets ruby-on-rails nginx unicorn digital-ocean

我正在使用Digital Ocean Droplet进行导轨应用.我成功地部署了第一个应用程序,但现在面临着尝试部署第二个应用程序的问题.我使用unicorn作为app服务器,nginx作为web服务器.操作系统是Ubuntu 14.04

我已经在stackexchange网站上阅读了很多帖子,也在博客等上阅读过,但它们都不符合我的立场.我认为问题出在应用程序和系统文件夹/文件/配置结构上.我更加谨慎地改变系统配置文件.

在网络上的大多数例子中,每个人都在讨论unicorn.rb, rails_root/config/但我没有.相反,我的unicorn.conf里面有相同的内容/etc.

还有一个侦听第一个应用程序的套接字文件,我尝试了两个为我的第二个应用程序创建第二个 - 但它失败了.

我知道,我必须为第二个应用程序创建另一个独角兽配置,并且还必须做一些应该通过创建第二个套接字的结果.

但缺乏对系统管理的了解和理解使我陷入困境.

任何人都可以指导我这个问题吗?

如果需要,我可以提供更多文件.

第一个应用程序(路径/etc/sites-available/first_app)的nginx配置文件.

upstream app_server {
    server unix:/var/run/unicorn.sock fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/myfirstapp/public;
    server_name www.myfirstapp.com;
    index index.htm index.html index.php index.asp index.aspx index.cgi index.pl index.jsp;

    location / {
            try_files $uri/index.html $uri.html $uri @app;
    }


    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                    try_files $uri @app;
            }

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
    }
}

server {
    listen 80;
    server_name www.myfirstapp.com;
    return 301 $scheme://myfirstapp.com$request_uri;    
}
Run Code Online (Sandbox Code Playgroud)

第二个应用(/etc/sites-available/second_app)

upstream app_server_2 {
    server unix:/var/run/unicorn.app_two.sock fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/secondapp/public;
    server_name secondapp.com;
    index index.htm index.html index.php index.asp index.aspx index.cgi index.pl index.jsp;

    location / {
            try_files $uri/index.html $uri.html $uri @app;
    }


    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                    try_files $uri @app;
            }

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server_2;
    }
}

server {
    listen 80;
    server_name secondapp.com www.secondapp.com;
    return 301 $scheme://secondapp.com$request_uri; 
}
Run Code Online (Sandbox Code Playgroud)

(/etc/unicorn.conf)

listen "unix:/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/myfirstapp"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"
Run Code Online (Sandbox Code Playgroud)

小智 0

这可能没有得到解答,因为您应该只使用 2 个独立的 Droplet,而不是尝试使这项工作正常进行(对于那些不熟悉服务器和部署内容的人来说,这将是一场噩梦)。Rails 有很多方法可以通过互联网互连 2 个应用程序。

如果您需要共享数据库,您甚至可以设置第三个 Droplet(尽管不需要)并从那里托管集中式数据库,并将两个应用程序连接到它。这也为您提供了很大的可扩展性。

当然,除非我误解了你想要做什么。

如果您使用 2 个 Droplet,并且语法是我们善变的情妇,请向我们提供更多详细信息。