Nginx无法运行Rails页面

时间:2013-12-03 08:31:19

标签: ruby-on-rails nginx

我想使用nginx作为我的Rails开发服务器。我安装了nginxpassenger

我的nginx配置文件是:

http{
      passenger_root /home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.26;
      passenger_ruby /home/hxh/.rvm/wrappers/ruby-1.9.3-p448/ruby;
      include       mime.types;
      default_type  application/octet-stream;
      server {
        listen       80;
        server_name  localhost;
        root /home/hxh/share/ruby/sport;
        passenger_enabled on;
        rails_env development;
       }
}

但是当我运行服务器时,我收到了错误:

404 Not Found

nginx/1.4.4

为什么nginx没有识别Rails页面。

2 个答案:

答案 0 :(得分:1)

看起来你错过了几个设置。

尝试使用以下配置,它应该可以工作。

http {
  passenger_root /home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.26;
  passenger_ruby /home/hxh/.rvm/wrappers/ruby-1.9.3-p448/ruby;
  include       mime.types;
  default_type  application/octet-stream;
  passenger_max_pool_size 10;
  access_log  off;
  sendfile        on;
  keepalive_timeout  65;
  gzip  on;


  server {
    listen       80;
    server_name  localhost;
    location / {
      root   /home/hxh/share/ruby/sport/public;
      passenger_enabled on;
      rails_env production;
    }
  }
}

注意:

  1. 您缺少位置

  2. 您的应用程序根目录应指向公用文件夹

  3. 应用程序根目录应具有完全执行权限

答案 1 :(得分:1)

如果root确实是您的项目文件夹,则需要将/home/hxh/share/ruby/sport指向公共文件夹,然后将其替换为/home/hxh/share/ruby/sport/public