我需要使用/ browse /
在子uri下运行我的Rails应用程序这是我公司的根域WEBSITE.COM
我的应用的根域应该以{{1}}
开头但是如果我在路径文件中添加https://WEBSITE.COM/browse
,我总是得到异常No route matches
。
我该怎么做才能解决问题?
scope ENV['RAILS_RELATIVE_URL_ROOT'] do
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
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
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'
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"
答案 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
的麻烦。