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

时间:2016-04-03 12:02:39

标签: ruby-on-rails sockets nginx unicorn digital-ocean

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

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

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

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

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

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

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

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

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

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

第二个应用(/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; 
}

/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"

1 个答案:

答案 0 :(得分:0)

这可能没有得到解决,因为你应该只使用2个独立的水滴,而不是尝试使这项工作(对于那些不熟悉服务器和部署的人来说,这将是一个噩梦)。 Rails有很多方法可以跨互联网互连2个应用程序。

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

当然,除非你误解了你想要做的事情。

如果你正在使用2个水滴,语法是我们变化无常的情妇,请与我们联系。