ruby-on-rails - puma 中的 HTTPS 重定向仅适用于基本 URL
问题描述
我的 puma 服务器从 http -> https (开发中)重定向,但只有一个 URL: localhost:3000
。一旦我在末尾添加任何内容(即localhost:3000/index
),它就不再重定向(并且页面错误)。
是否有我缺少的配置选项(或需要注释掉)?我目前有:
ssl_bind 'localhost', '3000' { ... }
在 config/puma.rb 和
force_ssl = true
config/environments/development.rb 中。
解决方案
force_ssl
应该将所有来自 http 端口的请求重定向到 https,当您尝试通过 http 连接到 https 端口时,它无法执行任何操作。
http 和 https 应该绑定到不同的端口(bind
和ssl_bind
选项)。习惯上在 3000 端口有 http 开发服务器,所以在其他端口绑定 ssl(例如 - 8443,https 的标准是 443,但它是特权)
还为开发指定 ssl_options 进行重定向:
config.ssl_options = { redirect: { status: 307, port: 8443 } }
推荐阅读
- windows - SendKeys.SendWait 不支持某些修饰符吗?
- python - 从运行循环启动异步循环
- javascript - 悬停时显示工具提示的 HTML 元素
- ssl - 基于操作系统的证书(ca-bundle.crt)使用 smtp_tls_CAfile 可以正常工作吗
- domain-driven-design - 如何检查将子 DDD 实体添加到父(树状结构)实体是否不会在另一棵树中循环
- scala - 类型与 akka.http.scaladsl.server.Route 不匹配
- node.js - 我有安装 better-sqlite3 的问题
- swift - 如何将图像和按钮居中到另一个按钮
- android - 我们可以像在 Dagger 中一样使用牙签在 Presenter 中注入“视图”吗?
- applescript - 如何使用显示对话框显示复合图标