我已经build立了我的rails应用程序,效果很好。 不幸的是,在网站的https://版本中,我的资产都没有被提供…任何想法为什么会发生这种情况? 所有资产都通过http://提供,但没有任何通过https://
帮帮我?
=============代码==============
upstream unicorn { server unix:/tmp/unicorn.XXX.sock fail_timeout=0; } server { listen 80 default; server_name example.com; root /home/deployer/apps/XXX/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-Proto http; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 5G; keepalive_timeout 10; send_timeout 240; sendfile_max_chunk 5m; } server { listen 443; server_name example.com; root /home/webuser/apps/XXX/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri @non-ssl-redirect @unicorn; location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 5G; keepalive_timeout 10; ssl on; ssl_certificate /etc/Nginx/ssl/server.crt; ssl_certificate_key /etc/Nginx/ssl/server.key; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP; ssl_session_cache shared:SSL:10m; send_timeout 240; sendfile_max_chunk 5m; }
Rails 3.2使用Thin和Apache的资产pipe道,没有find资产
这听起来像你的资产主机配置硬连线到http 。 当您通过https查看页面,但通过http加载资源时,许多浏览器会阻止资源或显示警告。
解决这个问题的最简单的方法是设置一个不包含协议的Rails asset_host ,该协议应该继承从其加载的页面的协议。
例如:
# Use just the asset host domain name for Rails pages config.action_controller.asset_host = "assets.mycompany.com" # Specify HTTP for ActionMailer messages,since they don't have a protocol to inherit config.action_mailer.asset_host = "http://assets.mycompany.com"
如果您使用https协议正确地包含您的资产,但是它们无法加载 – 您的资产的主机名和SSL证书之间可能存在SSL证书名称不匹配。 例如,如果您使用自定义域名直接从S3提供资产,那么S3 SSL证书(* .s3.amazonaws.com)将无法匹配assets.yourcompany.com并导致SSL错误,从而阻止资产加载。
在这种情况下,唯一的解决方法是使用允许自定义SSL证书匹配您的主机名的资产主机或CDN,或者还原为与您的提供商SSL证书相匹配的公共主机名。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。