suburi没有使用nginx,它给了我'没有路由匹配'的例外

时间:2015-10-20 13:51:23

标签: ruby-on-rails-4 nginx

我需要使用/ browse /

在子uri下运行我的Rails应用程序

这是我公司的根域WEBSITE.COM

我的应用的根域应该以{{1​​}}

开头

但是如果我在路径文件中添加https://WEBSITE.COM/browse,我总是得到异常No route matches

我该怎么做才能解决问题?

ENV

  • ENV [ 'RAILS_RELATIVE_URL_ROOT'] = /浏览/

的routes.rb

scope ENV['RAILS_RELATIVE_URL_ROOT'] do

application.rb中

scope ENV['RAILS_RELATIVE_URL_ROOT'] do
    get 'browse/category_detail'
    get '*path' => redirect('/')
end

生产日志中的错误

  class Application < Rails::Application
    config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
  end

nginx.conf

I, [2015-10-20T07:07:15.956058 #30522]  INFO -- : Started GET "/" for 127.0.0.1 at 2015-10-20 07:07:15 +0000
F, [2015-10-20T07:07:15.957575 #30522] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/"):

#UPDATE

访问日志

如果我删除路线中的server { listen 443; server_name WEBSITE.COM; location /browse { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unix:/tmp/puma.broswe.sock:/; } }%

一切都很好但是网址助手会被破坏,

这就是session_destroy_url将是scope ENV['RAILS_RELATIVE_URL_ROOT']但不是https://WEBSITE.COM/session/destroy

当我尝试访问https://WEBSITE.COM/browse/session/destroy

https://WEBSITE.COM/browse

当我尝试访问 I, [2015-10-22T00:14:18.847598 #22300] INFO -- : Started GET "/" for 127.0.0.1 at 2015-10-22 00:14:18 +0000 F, [2015-10-22T00:14:18.848971 #22300] FATAL -- : ActionController::RoutingError (No route matches [GET] "/"): actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app' railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call' activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged' activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged' activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged' railties (4.2.0) lib/rails/rack/logger.rb:20:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call' rack (1.6.1) lib/rack/methodoverride.rb:22:in `call' rack (1.6.1) lib/rack/runtime.rb:18:in `call' activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call' rack (1.6.1) lib/rack/sendfile.rb:113:in `call' dragonfly (0.9.15) lib/dragonfly/middleware.rb:13: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 (4.2.0) lib/rails/engine.rb:518:in `call' railties (4.2.0) lib/rails/application.rb:164:in `call' rack (1.6.1) lib/rack/urlmap.rb:66:in `block in call' rack (1.6.1) lib/rack/urlmap.rb:50:in `each' rack (1.6.1) lib/rack/urlmap.rb:50:in `call' puma (2.11.3) lib/puma/configuration.rb:51:in `call' puma (2.11.3) lib/puma/server.rb:507:in `handle_request' puma (2.11.3) lib/puma/server.rb:375:in `process_client' puma (2.11.3) lib/puma/server.rb:262:in `block in run' puma (2.11.3) lib/puma/thread_pool.rb:104:in `call' puma (2.11.3) lib/puma/thread_pool.rb:104:in `block in spawn_thread'

https://WEBSITE.COM/browse/browse/1

Nginx日志

  

https://WEBSITE.COM//browse

I, [2015-10-22T00:15:32.391853 #22300]  INFO -- : Started GET "/browse/1" for 127.0.0.1 at 2015-10-22 00:15:32 +0000
F, [2015-10-22T00:15:32.393190 #22300] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/1"):
  actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.1) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
  dragonfly (0.9.15) lib/dragonfly/middleware.rb:13: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 (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  rack (1.6.1) lib/rack/urlmap.rb:66:in `block in call'
  rack (1.6.1) lib/rack/urlmap.rb:50:in `each'
  rack (1.6.1) lib/rack/urlmap.rb:50:in `call'
  puma (2.11.3) lib/puma/configuration.rb:51:in `call'
  puma (2.11.3) lib/puma/server.rb:507:in `handle_request'
  puma (2.11.3) lib/puma/server.rb:375:in `process_client'
  puma (2.11.3) lib/puma/server.rb:262:in `block in run'
  puma (2.11.3) lib/puma/thread_pool.rb:104:in `call'
  puma (2.11.3) lib/puma/thread_pool.rb:104:in `block in spawn_thread'
  

https://WEBSITE.COM//browse/123

    10.0.0.97 - - [25/Oct/2015:09:24:45 +0000] "GET /browse HTTP/1.1" 404 715 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
    10.0.0.97 - - [25/Oct/2015:09:24:45 +0000] "GET /browse HTTP/1.1" 404 715 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"

1 个答案:

答案 0 :(得分:0)

  

...的.com /浏览/浏览/ 1

这是因为你使用proxy_redirect的方式从/browse开始使用$uri部分nginx剥离:

location /browse {
    proxy_pass http://unix:/tmp/puma.broswe.sock:/;
}

如果您的意图 NOT 在事物上游时剥离/browse,那么这就是您应该拥有的:

location /browse {
    proxy_pass http://unix:/tmp/puma.broswe.sock:/browse;
}

或者这个:

location /browse {
    proxy_pass http://unix:/tmp/puma.broswe.sock:;
}

是的,原文中的额外尾随/导致您在上游错过/browse的麻烦。