【发布时间】: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