Rails with nginx not serving CSS or JS with HTTPS

时间:2015-11-12 12:07:19

标签: ruby-on-rails nginx

I have a rails 4 application configured to use passenger and nginx. The application works as expected over HTTP, however when I use HTTPS the CSS and JS files are not served (although the images and text are).

My nginx config file is as follows:

server {
        listen       80;
        listen 443 ssl;
        server_name  divvyup.com.au;
        root /home/duroot/www/rails/DivvyUp/current/public;
        ssl_certificate      divvyup.com.au.chained.crt;
        ssl_certificate_key  divvyup.com.au.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        passenger_enabled on;
        location /assets/ {
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

My production.rb file contains:

config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
  config.assets.digest = true
  config.assets.version = '1.0'
  config.force_ssl = false

Any help would be great...

1 个答案:

答案 0 :(得分:1)

我找到了答案。

我已将asset_host指令设置为包含http:强制将资产作为HTTP提供。

按如下方式更新指令解决了问题:

config.action_controller.asset_host = 'www.divvyup.com.au'