【问题标题】:Deploying multiple Rails applications to DigitalOcean将多个 Rails 应用程序部署到 DigitalOcean
【发布时间】:2016-07-22 23:04:48
【问题描述】:

我正在将 Digital Ocean 液滴用于 Rails 应用程序。我已经成功地部署了第一个应用程序,但现在在尝试部署第二个应用程序时遇到了问题。我使用 unicorn 作为应用服务器,使用 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"

【问题讨论】:

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


    【解决方案1】:

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

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

    当然,除非我误解了你的意图。

    如果您使用 2 个液滴,而语法是我们善变的情妇,请联系我们,了解更多细节。

    【讨论】:

    • 是的,我对服务器/部署的东西不太熟悉。所以,我买了(或者它的确切动词)第二个水滴-))
    猜你喜欢
    • 2017-03-16
    • 2018-10-31
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 2018-08-22
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多