以 HTTPS 模式运行本地服务器很多时候都很有用,而不仅仅是 facebook api。
尽管如此,Rails 仍然不提供简单的方法 https://www.devmynd.com/blog/rails-local-development-https-using-self-signed-ssl-certificate/以 SSL 模式运行 Rails 服务器。但有几种方法可以实现这一目标:
Use thin
服务器而不是 puma/webrick Rails 默认服务器
thin
服务器允许您以最小的努力在 SSL 模式下运行应用程序:
Edit config/application.rb
并添加:
config.force_ssl = true
Start thin
server:
$ thin start --ssl
请在此处查看有关此内容的完整信息:如何在两分钟内启用SSL for Rails开发环境? https://blog.botreetechnologies.com/enable-ssl-in-developement-using-thin-2a4bd1af500d
使用 http 隧道工具,例如ngrok
类似的工具ngrok https://ngrok.com/允许您轻松创建从本地主机到互联网的隧道 - 它还创建了两者http://
and https://
为您提供的端点:
$ rails s -p 3000
$ ./ngrok http 3000
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 7 hours, 59 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://2608e936.ngrok.io -> localhost:3000
Forwarding https://2608e936.ngrok.io -> localhost:3000
复制生成的网址(例如https://2608e936.ngrok.io
并用它来访问您的本地服务器。