Mat*_*ugh 8 ruby ssl ruby-on-rails
我刚刚在我的网站上安装了SSL证书.不幸的是,它破坏了登录功能.在网站上提交登录表单后,它只会重定向到主页.检查rails日志会显示以下错误:
(https://example.com) didn't match request.base_url (http://example.com)
Run Code Online (Sandbox Code Playgroud)
这是我的virtualhosts文件.我想我需要以某种方式强制使用SSL?
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin hello@example.com
ServerName example.com
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile /home/user/sharetribe/lib/certificates/www_example_com.crt
SSLCertificateKeyFile /home/user/sharetribe/lib/certificates/example.com.key
SSLCertificateChainFile /home/user/sharetribe/lib/certificates/www_example_com.ca-bundle
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
Rah*_*ari 19
由于 Rails 应用程序服务器在启用 SSL 的网络服务器后面运行。但是应用服务器并没有意识到它并继续使用 HTTP 协议。由于它request.base_url给出了 HTTP URL。
要让应用服务器知道 SSL 已启用并使用 https 协议,您需要明确告诉应用服务器。
在 Nginx 网络服务器中,我使用过,
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
Run Code Online (Sandbox Code Playgroud)
对于 Apache Web 服务器,需要找到类似的设置。
我认为使用config.force_ssl = true可以解决问题但不能正确,因为此配置将所有 HTTP 请求更改为 HTTPS。意味着如果有人使用 HTTP 请求,它将重定向到 HTTPS。config.force_ssl = true如果您将 URL 发送到客户端,则在 API 的情况下将不起作用。
Qwe*_*tie 16
只是遇到同样的错误.在config/environments/production.rb确保你已经设置:
config.force_ssl = true
Run Code Online (Sandbox Code Playgroud)
虽然与此问题没有严格关联,但在设置此设置后,您需要确保您的反向代理(如果有的话)设置为通过将X-Forwarded-Proto代理从头代码发送到rails来转发用于rails的协议.这样做的方式取决于您使用的反向代理(Apache,nginx等)以及如何配置它,因此最好查找您正在使用的反向代理的特定文档.
使用Cloudflare的Flexible SSL时遇到类似的问题。我将其更改为“完全”,并在我的Heroku服务器上激活了SSL。
在此处找到解决方案:http : //til.obiefernandez.com/posts/875a2a69af-cloudflare-flexible-ssl-mode-breaks-rails-5-csrf
| 归档时间: |
|
| 查看次数: |
6159 次 |
| 最近记录: |