如何让 Sinatra 通过 HTTPS/SSL 工作?
正如标题所示,谷歌没有提供任何与此相关的有用信息。
如何为 Sinatra 应用程序设置和配置 HTTPS/SSL?
如何创建 HTTPS 路由?
我以前从未在我的应用程序中使用过 HTTPS,也没有调整 Rack/其他内容的经验,所以我很欣赏详细的答案。
As the title says, Google doesn't give anything useful concerning this.
How do I set up and configure HTTPS/SSL for Sinatra apps?
How do I create a HTTPS route?
I have never used HTTPS for my apps before and have no experience tweaking Rack/whatever, so I appreciate detailed answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这似乎对我有用:
[提示 http://www .networkworld.com/columnists/2007/090507-dr-internet.html]
this seems to do it for me:
[hat tip to http://www.networkworld.com/columnists/2007/090507-dr-internet.html]
我认为使用 rack-ssl 是最好的选择。
然后你只需执行以下操作:
所有
http://
调用都会重定向到https://
I think using rack-ssl is the best option.
Then you just do:
and all
http://
calls are redirected tohttps://
我想您需要设置您的 Web 服务器(而不是 Sinatra)才能使用 SSL。在 Sinatra 中,您可以使用
request.secure?
方法来检查 SSL 使用情况。SSL + Nginx:第一篇文章,第二个。
I guess you need to setup your Web-server, not Sinatra, to work with SSL. In Sinatra you can use the
request.secure?
method to check for the SSL usage.SSL + Nginx: the first article, the second one.
我修改了 richard_bw 的代码,以便能够使用 Ctrl+C 关闭或重新启动它:
I modified code of richard_bw as to be able close or restart it with Ctrl+C:
为了避免多个服务器,这里的 webrick 特定答案很好,但 webrick 特定。
使用Puma时,可以简化配置:
For avoiding multiple servers, the webrick specific answers here are fine, but webrick specific.
When using Puma, the configuration can be simplified:
经过广泛搜索后,我能找到的最简单的解决方案是 Frank 此处。
只需将以下内容放在 Sinatra 经典应用程序的顶部即可强制您的应用程序使用 HTTPS:
The easiest solution I could find after a broad search, is the solution posted by Frank here.
Simply place the following at the top of your Sinatra classic app to force your application to use HTTPS:
处理程序已从机架库移至机架库。以下是对我有用的
The handler has been moved from the rack library to rackup. Below is what worked for me