新手问题 Nginx + Passenger 部署 rails,访问 /rails/info/properties 出现 404

Standme · 2012年04月04日 · 最后由 jiffies 回复于 2012年05月31日 · 4371 次阅读

由于受到触动,呵呵,开始学习 rails,目前的进度是可以在本机(MBA)搭建好 rails 的学习环境了,并且正在学习那个笨方法学习 ruby 语言,学习到了第五节,每节都自己写代码,并在运行代码之前写注释,注释内容是我自己理解的每个语句的作用并应该出现的结果,代码运行之后方便对照。

同时也在虚拟机环境中调试 rail 的生产环境,因为我的服务器是 Debian,所以我也在虚拟机下安装了 debian,目前可以正常搞定安装环境,而且也自行编译了 Nginx 和 Passenger,设置完成之后,久违的那个欢迎页面出现,

但是当点击“About your application’s environment”那个链接的时候,出现了“404 Not Found nginx/1.0.14“的错误。那个链接对应的URL是:http://mydomain/rails/info/propertiesNginx的配置文件:,很是奇怪,以下是我的

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    passenger_root /home/standme/.rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.11;
     passenger_ruby /home/standme/.rvm/wrappers/ruby-1.9.3-p125/ruby;
    #gzip  on;
    server {
    autoindex on;
        root /home/standme/webroot;
       listen       80;
        server_name  localhost;        
        location / {
            index  index.html index.htm index.php;
        }

    location ~ \.php {
    include fastcgi.conf;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    }
       error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  }
  server{
    listen 80;
      server_name standme;
      root /home/standme/webroot/demo/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
    location / {
    index index.html index.htm;
    }   
  }
}



不知道是哪里出问题了,请各位热心的朋友帮看看

PS:顺便说一句,如果用 rails 自带的那个 WEBrick 来启动服务的话,在 localhost:3000 看到的页面没有任何问题。

之前出现那个没有 JS runtime 的问题,使用 gem install execjs, gem install therubyracer 并在 Gemfile 里面 加载 gem 'execjs' gem 'therubyracer' 就木问题了,这个 JS runtime 的问题,在 Mac OS X 里面没发生。

顶一下,哪位来帮忙看看吧,服务器环境是 debian 6.0.4,nginx 1.0.14,rails 3.2.2,那个项目就是用 rails new demo 直接生成的,没有做任何修改。

在你刚接触的时候,别急着尝试用 Passenger 来跑,因为出错了你都不知道可以看 production.log 和 Nginx error.log

Nginx 的 error.log 内容是这样的

2012/04/05 12:55:57 [error] 2469#0: *3 open() "/home/standme/webroot/demo/public/assets/rails.png" failed (2: No such file or directory), client: 127.0.0.1, server: standme, request: "GET /assets/rails.png HTTP/1.1", host: "standme", referrer: "http://standme/"
2012/04/05 12:56:14 [error] 2469#0: *3 open() "/home/standme/webroot/demo/public/rails/info/properties" failed (2: No such file or directory), client: 127.0.0.1, server: standme, request: "GET /rails/info/properties HTTP/1.1", host: "standme", referrer: "http://standme/"


而 rails 的 production.log,内容是这样的:


Started GET "/assets/rails.png" for 127.0.0.1 at 2012-04-04 21:45:43 +0800

ActionController::RoutingError (No route matches [GET] "/assets/rails.png"):
  actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.2) lib/rails/engine.rb:479:in `call'
  railties (3.2.2) lib/rails/application.rb:220:in `call'
  railties (3.2.2) lib/rails/railtie/configurable.rb:30:in `method_missing'
  passenger (3.0.11) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.11) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.11) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/utils.rb:479:in `safe_fork'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:180:in `start'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.11) helper-scripts/passenger-spawn-server:99:in `<main>'




Started GET "/rails/info/properties" for 127.0.0.1 at 2012-04-04 21:45:50 +0800

ActionController::RoutingError (No route matches [GET] "/rails/info/properties"):
  actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.2) lib/rails/engine.rb:479:in `call'
  railties (3.2.2) lib/rails/application.rb:220:in `call'
  railties (3.2.2) lib/rails/railtie/configurable.rb:30:in `method_missing'
  passenger (3.0.11) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.11) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.11) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/utils.rb:479:in `safe_fork'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:180:in `start'
  passenger (3.0.11) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
  passenger (3.0.11) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.11) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.11) helper-scripts/passenger-spawn-server:99:in `<main>'


貌似是说路由设置有问题?

刚开始接触就想把生产环境搞好也是为了增加学习的信心啊,开发环境和服务器部署的生产环境我都能搞好的话,接下来我就专心学习语言了。 :(

通常都是 precompile 和目录权限的问题

rails/info/properties 在 production 下无效吧,是内建的 Rails::InfoController

需要 登录 后方可回复, 如果你还没有账号请 注册新账号