Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么在Rails 4应用程序(OpenShift)中从HTTPS重定向到HTTP失败?_Ruby On Rails_Ruby On Rails 4_Openshift - Fatal编程技术网

Ruby on rails 为什么在Rails 4应用程序(OpenShift)中从HTTPS重定向到HTTP失败?

Ruby on rails 为什么在Rails 4应用程序(OpenShift)中从HTTPS重定向到HTTP失败?,ruby-on-rails,ruby-on-rails-4,openshift,Ruby On Rails,Ruby On Rails 4,Openshift,当用户使用HTTP时,我可以成功地将其重定向到HTTPS(SSL)变体,如下所示: 将_重定向到{协议:'https://',域:'ssl.tld'} 但是,当我想反向执行时,它会创建一个无限重定向循环。我试过几种变体。提到一些: 将_重定向到{协议:'http://',域:'nonssl.tld'} 将_重定向到“http://nonssl.tld#{request.fullpath}“ 循环,根据日志: 000.000.000.000---[21/Apr/2016:18:50:04-0100

当用户使用HTTP时,我可以成功地将其重定向到HTTPS(SSL)变体,如下所示:

将_重定向到{协议:'https://',域:'ssl.tld'}

但是,当我想反向执行时,它会创建一个无限重定向循环。我试过几种变体。提到一些:

将_重定向到{协议:'http://',域:'nonssl.tld'}

将_重定向到“http://nonssl.tld#{request.fullpath}“

循环,根据日志:

000.000.000.000---[21/Apr/2016:18:50:04-0100]“GET/en HTTP/1.1”302887https://ssl.tld/en/users/sign_in“”=此处的用户代理“

鉴于
https://ssl.tld/en/users/sign_in
显然是重定向前的推荐人/当前页面

我想知道为什么
GET
会显示一个路径而不是一个URL——特别是考虑到
重定向到“http://nonssl.tld#{request.fullpath}“
应该被明确地视为绝对URL,根据文档


更新以下是应用程序控制器的
操作前的相关部分

exceptions = ['errors', 'subscriptions', 'users']
ssl_is_mandatory = ! exceptions.include?(controller_name)
currently_on_ssl = request.ssl?

if currently_on_ssl
  if !current_user && !ssl_is_mandatory
    logger.debug "#{__method__}: Visitor currently on SSL, but SSL not desired. Redirecting to non_ssl"
    redirect_to "http://my.domain#{request.fullpath}"
  end

else
  if current_user || ssl_is_mandatory
    logger.debug "#{__method__}: Currently on no-SSL, but user in session or SSL mandatory. Redirecting to ssl"
    redirect_to { protocol: 'https://', domain: 'my.ssldomain' }
  end
end
def debug_toggle_ssl
  if params[:x].eql?('yes')
    redirect_to "http://NONSSL.tld#{request.fullpath}"
  end
end

更新:根据Marc在评论中的要求,以下是请求标题:

SSL域的请求头

# curl -s -I https://SSL.tld
HTTP/1.1 302 Found
Date: Mon, 02 May 2016 23:33:34 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
X-Request-Id: 8d182c5e-cec6-46c0-b845-eafe2d313fe2
X-Runtime: 0.005948
X-Powered-By: Phusion Passenger 4.0.18
Location: https://SSL.tld/en
Content-Length: 895
Status: 302 Found
Content-Type: text/html; charset=utf-8
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/

# curl -s -I https://SSL.tld/en
HTTP/1.1 200 OK
Date: Mon, 02 May 2016 23:33:52 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
ETag: "acf44db83201e4da25659ab8545936b3"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 671d9407-0cdd-4401-9537-abff660e1b18
X-Runtime: 0.078496
X-Powered-By: Phusion Passenger 4.0.18
Content-Length: 10964
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-control: private
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/
Vary: Accept-Encoding
# curl -s -I http://NONSSL.tld
HTTP/1.1 302 Found
Date: Mon, 02 May 2016 23:34:16 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
X-Request-Id: 9f7b4341-0489-48fa-b15d-b45f787db690
X-Runtime: 0.007811
X-Powered-By: Phusion Passenger 4.0.18
Location: http://NONSSL.tld/en
Content-Length: 873
Status: 302 Found
Content-Type: text/html; charset=utf-8
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/

# curl -s -I http://NONSSL.tld/en
HTTP/1.1 200 OK
Date: Mon, 02 May 2016 23:34:47 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
ETag: "05294c86e7f806ebf2e90c5f52fd7497"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 25a0ac8c-6cba-4a83-9a15-b95474436a3e
X-Runtime: 0.290131
X-Powered-By: Phusion Passenger 4.0.18
Content-Length: 10877
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-control: private
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/
Vary: Accept-Encoding
非SL域的请求头

# curl -s -I https://SSL.tld
HTTP/1.1 302 Found
Date: Mon, 02 May 2016 23:33:34 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
X-Request-Id: 8d182c5e-cec6-46c0-b845-eafe2d313fe2
X-Runtime: 0.005948
X-Powered-By: Phusion Passenger 4.0.18
Location: https://SSL.tld/en
Content-Length: 895
Status: 302 Found
Content-Type: text/html; charset=utf-8
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/

# curl -s -I https://SSL.tld/en
HTTP/1.1 200 OK
Date: Mon, 02 May 2016 23:33:52 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
ETag: "acf44db83201e4da25659ab8545936b3"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 671d9407-0cdd-4401-9537-abff660e1b18
X-Runtime: 0.078496
X-Powered-By: Phusion Passenger 4.0.18
Content-Length: 10964
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-control: private
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/
Vary: Accept-Encoding
# curl -s -I http://NONSSL.tld
HTTP/1.1 302 Found
Date: Mon, 02 May 2016 23:34:16 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
X-Request-Id: 9f7b4341-0489-48fa-b15d-b45f787db690
X-Runtime: 0.007811
X-Powered-By: Phusion Passenger 4.0.18
Location: http://NONSSL.tld/en
Content-Length: 873
Status: 302 Found
Content-Type: text/html; charset=utf-8
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/

# curl -s -I http://NONSSL.tld/en
HTTP/1.1 200 OK
Date: Mon, 02 May 2016 23:34:47 GMT
Server: Apache/2.2.15 (Red Hat)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
ETag: "05294c86e7f806ebf2e90c5f52fd7497"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 25a0ac8c-6cba-4a83-9a15-b95474436a3e
X-Runtime: 0.290131
X-Powered-By: Phusion Passenger 4.0.18
Content-Length: 10877
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-control: private
Set-Cookie: GEAR=local-554148915973ca816300021b; path=/
Vary: Accept-Encoding

更新

在执行操作之前,我进一步简化了应用程序控制器的
中的重定向代码:

exceptions = ['errors', 'subscriptions', 'users']
ssl_is_mandatory = ! exceptions.include?(controller_name)
currently_on_ssl = request.ssl?

if currently_on_ssl
  if !current_user && !ssl_is_mandatory
    logger.debug "#{__method__}: Visitor currently on SSL, but SSL not desired. Redirecting to non_ssl"
    redirect_to "http://my.domain#{request.fullpath}"
  end

else
  if current_user || ssl_is_mandatory
    logger.debug "#{__method__}: Currently on no-SSL, but user in session or SSL mandatory. Redirecting to ssl"
    redirect_to { protocol: 'https://', domain: 'my.ssldomain' }
  end
end
def debug_toggle_ssl
  if params[:x].eql?('yes')
    redirect_to "http://NONSSL.tld#{request.fullpath}"
  end
end
现在,让我们来重现这个问题:

  • 设法去
  • 注意循环是如何产生的(从未被请求)

  • 这可能是OpenShift联机问题吗?您是否在环境配置或任何控制器中将force_ssl设置为true?在整个项目范围内搜索force_ssl并通知我们。
    force_ssl
    处于默认值(任何地方都不会出现)。请注意,我可以在HTTP中很好地浏览应用程序。当我进入登录页面时,操作前的
    确保我切换到SSL变量。但是,一旦我再次尝试离开该站点(没有实际登录),就会发生错误-即使我的
    在\u操作之前
    指示返回HTTP变体。我已经在问题中添加了源代码。您在web服务器中设置了重定向吗?可能您的web服务器(apache、nginx等)正在将http重定向到https