首页 > 解决方案 > puma 中的 HTTPS 重定向仅适用于基本 URL

问题描述

我的 puma 服务器从 http -> https (开发中)重定向,但只有一个 URL: localhost:3000。一旦我在末尾添加任何内容(即localhost:3000/index),它就不再重定向(并且页面错误)。

是否有我缺少的配置选项(或需要注释掉)?我目前有:
ssl_bind 'localhost', '3000' { ... }在 config/puma.rb 和
force_ssl = trueconfig/environments/development.rb 中。

标签: ruby-on-railsruby-on-rails-5pumapuma-dev

解决方案


force_ssl应该将所有来自 http 端口的请求重定向到 https,当您尝试通过 http 连接到 https 端口时,它无法执行任何操作。

http 和 https 应该绑定到不同的端口(bindssl_bind选项)。习惯上在 3000 端口有 http 开发服务器,所以在其他端口绑定 ssl(例如 - 8443,https 的标准是 443,但它是特权)

还为开发指定 ssl_options 进行重定向:

config.ssl_options = {  redirect: { status: 307, port: 8443 } }

推荐阅读