nginx 和 unicorn 上的多个 Rails 应用程序 [英] multiple rails apps on nginx and unicorn

查看:47
本文介绍了nginx 和 unicorn 上的多个 Rails 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Screencast 335 部署到 VPS 教程成功地设置了一个 rails 站点.现在我想在新域上添加另一个 rails 应用程序,但我对所需的步骤感到困惑.

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 required.

在上面的设置中,sites-available 或/etc/nginx/nginx.conf 没有变化.唯一的配置是在我的应用程序配置目录中的 unicorn.rb、unicorn_init.sh 和 nginx.conf 中.nginx.conf 文件如下所示:-

In the above setup, there are no changes to sites-available or /etc/nginx/nginx.conf. The only configuration is in unicorn.rb, unicorn_init.sh and nginx.conf in my apps config directory. The nginx.conf file looks like this:-

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

在我的 Capistrano 食谱中,我有这条线

In my Capistrano recipe I have this line

sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"

添加第二个域是否仅仅是在监听和取消对 server_name 部分的注释后删除默认延迟然后使用不同的上游套接字名称和第二个应用程序的服务器名称重复此配置文件的问题?这会起作用还是我需要将此文件传输到可用站点并创建指向启用站点的符号链接?

Is adding a second domain merely a matter of removing default deferred after listen and un-commenting the server_name section then repeating this config file with a different upstream socket name and server name for the second app? Will that work or do I need to transfer this file to sites-available and create a symbolic link to sites-enabled?

推荐答案

使用 Nginx 和 Unicorn 在一台主机上托管不同的应用程序真的很容易.

It is really easy to host different apps on one host with Nginx and Unicorn.

通过定义每个应用程序的socket 文件的不同名称可以获得的分离.当然,您应该在 nginx.confserver 部分中指向正确的 current/public 目录.

The separation you can get by defining different names of the socket files of each application. Of course you should point the right current/public directories in the server section of nginx.conf.

最后一步是在 unicorn_init.sh 文件中:在它的顶部,您应该将 APP_ROOT 更改为 current/public 应用程序的目录.

The last touch is in the unicorn_init.sh file: on the top of it you should change APP_ROOT with the full path to current/public directory of your application.

如果您的设置类似于 RailsCast 的设置,则所有其他事情都由 capistrano 完成.

If your setup is similar to the RailsCast's one, all the other things are done by capistrano .

这篇关于nginx 和 unicorn 上的多个 Rails 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆