URI::InvalidComponentError(错误组件(预期方案组件)::https):
URI::InvalidComponentError (bad component(expected scheme component): : https):
我正在 Ruby Rails 网络应用程序上工作,我使用 Devise for user/password 和 OmniAuth 使用社交媒体帐户进行身份验证。我也在使用 Nginx。
使用 username/password 的身份验证工作完美。但是当我将 ssl 证书添加到 Nginx 时。我现在可以登录了。但是当我注销时,我在标题 URI::InvalidComponentError (bad component(expected scheme component): : https):
中收到错误消息,并告诉我有一个异常生成自:
def check_scheme(v)
if v && parser.regexp[:SCHEME] !~ v
raise InvalidComponentError,
"bad component(expected scheme component): #{v}"
end
如何解决此问题才能使所有类型的身份验证正常工作?
更新
几乎每次使用网络应用程序重定向后都会抛出相同的异常。但无论如何重定向,事件用户登录。但它永远不会注销
*更新 2 *
This question 对我的问题有更详细的描述
This other question 是解决问题的另一种尝试
更新 3
当我尝试将 config.force_ssl = true
添加到我的环境 .rb
文件时,我在 ssl.error.log
中得到 "page not found" 和以下内容
2018/04/13 05:05:14 [error] 7317#0: *553 connect() failed (111: Connection refused) while connecting to upstream, client: <my laptop ip>, server: vps37181, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "<domain name>"
2018/04/13 05:05:14 [error] 7317#0: *553 open() "/var/www/<app-name>/public/50x.html" failed (2: No such file or directory), client: <my laptop ip>, server: vps37181, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "<domain name>"
更新 4
我当前在 /etc/nginx/conf.d/ssl.conf
的 nginx 配置是:
server {
listen 443 ssl;
server_name <server-name>;
client_max_body_size 15M;
ssl on;
ssl_certificate <.pem file path>;
ssl_certificate_key <.key file path>;
...
root <"public" directory inside my app directory>;
access_log <ssl.access.log path>;
error_log <ssl.error.log path>;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto: $scheme;
}
更新 5
从 Nginx 重定向到应用程序的每个请求后,我在应用程序控制台中得到以下信息:
Cannot render console from <my laptop ip>! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
URI::InvalidComponentError (bad component(expected scheme component): : https):
/home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb:322:in `check_scheme'
/home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb:363:in `scheme='
actionpack (5.1.5) lib/action_dispatch/routing/redirection.rb:35:in `serve'
actionpack (5.1.5) lib/action_dispatch/routing/redirection.rb:21:in `call'
actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:17:in `block in <class:Constraints>'
actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:46:in `serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:844:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/builder.rb:63:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.5) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:20:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.5) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
request_store (1.4.0) lib/request_store/middleware.rb:19:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.5) lib/rails/engine.rb:522:in `call'
puma (3.11.2) lib/puma/configuration.rb:225:in `call'
puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
puma (3.11.2) lib/puma/server.rb:438:in `process_client'
puma (3.11.2) lib/puma/server.rb:302:in `block in run'
puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
此消息不会阻止网站加载。但是当用户注销时(我正在使用 Devise 进行 username/password 用户身份验证)。该网站在浏览器中抛出我之前提到的错误:
URI::InvalidComponentError
bad component(expected scheme component): : https
Extracted source (around line #322):
def check_scheme(v)
if v && parser.regexp[:SCHEME] !~ v
raise InvalidComponentError, # line 322
"bad component(expected scheme component): #{v}"
end
我两次收到控制台错误消息。
更新 7
我 运行 我的服务器正在开发中。
我深入挖掘后发现:
URI::InvalidComponentError (bad component(expected scheme component): : https)
表示预期的是 : https
而收到的是 https
。
我尝试修改 check_shceme in /home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb
中的 parser.regexp[:SCHEME]
,它也批准了 : https
。但是现在,在注销时,它应该向
发送请求
https://<my domain name>/users/log_out
现在重定向到:
https://<my domain name>/users/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/
其中 :%20
表示空格。
问题出在 destory_user_session
路线上。不知怎的,它被另一个覆盖了。
我(暂时)解决了我的问题,方法是将 destory_user_session
的方法设置为 get
而不是 config/initializers/devise.rb
中的 delete
使用:
config.sign_out_via = :get
我正在 Ruby Rails 网络应用程序上工作,我使用 Devise for user/password 和 OmniAuth 使用社交媒体帐户进行身份验证。我也在使用 Nginx。
使用 username/password 的身份验证工作完美。但是当我将 ssl 证书添加到 Nginx 时。我现在可以登录了。但是当我注销时,我在标题 URI::InvalidComponentError (bad component(expected scheme component): : https):
中收到错误消息,并告诉我有一个异常生成自:
def check_scheme(v)
if v && parser.regexp[:SCHEME] !~ v
raise InvalidComponentError,
"bad component(expected scheme component): #{v}"
end
如何解决此问题才能使所有类型的身份验证正常工作?
更新
几乎每次使用网络应用程序重定向后都会抛出相同的异常。但无论如何重定向,事件用户登录。但它永远不会注销
*更新 2 *
This question 对我的问题有更详细的描述
This other question 是解决问题的另一种尝试
更新 3
当我尝试将 config.force_ssl = true
添加到我的环境 .rb
文件时,我在 ssl.error.log
2018/04/13 05:05:14 [error] 7317#0: *553 connect() failed (111: Connection refused) while connecting to upstream, client: <my laptop ip>, server: vps37181, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "<domain name>"
2018/04/13 05:05:14 [error] 7317#0: *553 open() "/var/www/<app-name>/public/50x.html" failed (2: No such file or directory), client: <my laptop ip>, server: vps37181, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "<domain name>"
更新 4
我当前在 /etc/nginx/conf.d/ssl.conf
的 nginx 配置是:
server {
listen 443 ssl;
server_name <server-name>;
client_max_body_size 15M;
ssl on;
ssl_certificate <.pem file path>;
ssl_certificate_key <.key file path>;
...
root <"public" directory inside my app directory>;
access_log <ssl.access.log path>;
error_log <ssl.error.log path>;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto: $scheme;
}
更新 5
从 Nginx 重定向到应用程序的每个请求后,我在应用程序控制台中得到以下信息:
Cannot render console from <my laptop ip>! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
URI::InvalidComponentError (bad component(expected scheme component): : https):
/home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb:322:in `check_scheme'
/home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb:363:in `scheme='
actionpack (5.1.5) lib/action_dispatch/routing/redirection.rb:35:in `serve'
actionpack (5.1.5) lib/action_dispatch/routing/redirection.rb:21:in `call'
actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:17:in `block in <class:Constraints>'
actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:46:in `serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:844:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/strategy.rb:190:in `call!'
omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call'
omniauth (1.8.1) lib/omniauth/builder.rb:63:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.5) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:20:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.5) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
request_store (1.4.0) lib/request_store/middleware.rb:19:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.5) lib/rails/engine.rb:522:in `call'
puma (3.11.2) lib/puma/configuration.rb:225:in `call'
puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
puma (3.11.2) lib/puma/server.rb:438:in `process_client'
puma (3.11.2) lib/puma/server.rb:302:in `block in run'
puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
此消息不会阻止网站加载。但是当用户注销时(我正在使用 Devise 进行 username/password 用户身份验证)。该网站在浏览器中抛出我之前提到的错误:
URI::InvalidComponentError
bad component(expected scheme component): : https
Extracted source (around line #322):
def check_scheme(v)
if v && parser.regexp[:SCHEME] !~ v
raise InvalidComponentError, # line 322
"bad component(expected scheme component): #{v}"
end
我两次收到控制台错误消息。
更新 7
我 运行 我的服务器正在开发中。
我深入挖掘后发现:
URI::InvalidComponentError (bad component(expected scheme component): : https)
表示预期的是 : https
而收到的是 https
。
我尝试修改 check_shceme in /home/tamer/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/uri/generic.rb
中的 parser.regexp[:SCHEME]
,它也批准了 : https
。但是现在,在注销时,它应该向
https://<my domain name>/users/log_out
现在重定向到:
https://<my domain name>/users/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/:%20https://<my domain name>/
其中 :%20
表示空格。
问题出在 destory_user_session
路线上。不知怎的,它被另一个覆盖了。
我(暂时)解决了我的问题,方法是将 destory_user_session
的方法设置为 get
而不是 config/initializers/devise.rb
中的 delete
使用:
config.sign_out_via = :get