Nginx +乘客:多个域需要指向不同的根

时间:2012-08-16 22:17:49

标签: ruby-on-rails ruby nginx passenger

与Nginx和乘客一起工作。我已经成功地让一个应用程序/域正常工作。但是对于我的服务器,我有2个以上的域名,我计划从nginx服务器到各自的根目录,每个rails应用程序都将存在。

我尝试了很多技巧,但都没有效果。所有域都采用第一个根设置,而不是它们应该是根。

这是我的nginx.conf文件:

  server { 
    listen 80;
    server_name www.danielcw.info;
    root /root/public/danielcw.info/public;   # <--- be sure to point to 'public'!
    access_log  /root/public/danielcw.info/log/access.log;
    error_log /root/public/danielcw.info/log/error.log;
    passenger_enabled on;
    rails_env development;
  } 

  server {
    listen 80;
    server_name www.ericoppi.com;
    root /root/public/ericcoppi.com/public;   # <--- be sure to point to 'public'!
    access_log  /root/public/ericcoppi.com/log/access.log;
    error_log /root/public/ericcoppi.com/log/error.log;
    passenger_enabled on;
    rails_env development;
  }

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

该配置应该正常工作 - 我唯一的改变就是通过nginx提供www和no-www:

  server { 
    listen 80;
    server_name danielcw.info www.danielcw.info;
    root /root/public/danielcw.info/public;
    access_log  /root/public/danielcw.info/log/access.log;
    error_log /root/public/danielcw.info/log/error.log;
    passenger_enabled on;
    rails_env development;
  } 

  server {
    listen 80;
    server_name ericoppi.com www.ericoppi.com;
    root /root/public/ericcoppi.com/public;
    access_log  /root/public/ericcoppi.com/log/access.log;
    error_log /root/public/ericcoppi.com/log/error.log;
    passenger_enabled on;
    rails_env development;
  }

确保在编辑配置文件后重新启动了nginx。