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

查看:72
本文介绍了Nginx和独角兽上的多个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.

在上述设置中,可用站点或/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和独角兽上的多个Rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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