在亚马逊EC2生产中,ActionController :: RoutingError(没有路由匹配[GET])

时间:2015-11-25 11:04:27

标签: ruby-on-rails nginx amazon-ec2 passenger

我已经使用nginx和乘客在amazon ec2实例上部署了我的应用程序,并且在我调用fd_set input_set; struct timeval timeout; int ready_for_reading = 0; FD_ZERO(&input_set); FD_SET(0, &input_set); timeout.tv_sec = 5; timeout.tv_usec = 0; ready_for_reading = select(1, &input_set, NULL, NULL, &timeout); if(ready_for_reading) { char * returnCommand = Cmd_Debug_GetResponse(); printf("OK : %s\n", returnCommand); } else { printf("5 secs are over\n"); } 时它正常工作,并且它的工作完全正如我想要运行。

但是当我调用网址api.subdomain.domain.com/admin时,我却遇到了错误。它适当地在当地开发和生产模式。只有API调用无效。

我使用了api.subdomain.domain.com/v1/productsruby 2.2.2

如果有人想了解有关此问题的详细信息,请与我们联系。

rails 4.2.3

我的routes.rb文件:

ActionController::RoutingError (No route matches [GET] "/v1/products"):
App 7773 stdout:   actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
App 7773 stdout:   actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
App 7773 stdout:   railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
App 7773 stdout:   railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
App 7773 stdout:   activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
App 7773 stdout:   activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
App 7773 stdout:   activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
App 7773 stdout:   railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
App 7773 stdout:   actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
App 7773 stdout:   rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
App 7773 stdout:   rack (1.6.4) lib/rack/runtime.rb:18:in `call'
App 7773 stdout:   activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
App 7773 stdout:   actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
App 7773 stdout:   rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
App 7773 stdout:   railties (4.2.3) lib/rails/engine.rb:518:in `call'
App 7773 stdout:   railties (4.2.3) lib/rails/application.rb:165:in `call'
App 7773 stdout:   /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
App 7773 stdout:   /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 7773 stdout:   /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 7773 stdout:   /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 7773 stdout:   /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
App 7773 stdout: 

当我做rake路线然后我得到了这条路线

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

  constraints :subdomain => 'api' do
    namespace :api, path: nil, defaults: {format: 'json'} do
      namespace :v1 do
        get "/products" => "products#all_details"
      end

      namespace :v2 do
        get "/products" => "products#all_details"
      end
    end
  end
end

1 个答案:

答案 0 :(得分:1)

我找到了解决方法。这里的问题是针对子域名的。这里我有2个子域和rails默认设置为TLD(Top Level Domain)。我用2增加了它,它为我工作。

这里将set 2作为值添加到production.rb

下面的配置中
config.action_dispatch.tld_length = 2

注意:实际上TLD不用于预子域,但它对我有用,所以我在这里给出了解决方案。它用于.com,.co.in ..