资源被解释为样式表,但以MIME类型的文本/纯文本,Rails 5进行传输

时间:2019-01-05 14:16:54

标签: ruby-on-rails amazon-web-services nginx ruby-on-rails-5.1

我正在AWS上运行Rails 5应用程序,并已使用以下nginx.conf文件配置了nginx。 问题是nginx为我的application.css文件提供了错误的mime类型。有人可以指出出什么问题了吗?

/etc/nginx/nginx.conf

   http {

            include       /etc/nginx/mime.types;
            default_type  application/octet-stream;
            sendfile     on;
            tcp_nopush   on;

            upstream puma {
              server unix:/home/deployer/website/shared/tmp/sockets/puma.sock;
            }

            server {
              listen 80 default_server deferred;
              # server_name example.com;

              root /home/deployer/website/current/public;
              access_log /home/deployer/website/current/log/nginx.access.log;
              error_log /home/deployer/website/current/log/nginx.error.log info;


              location ~* ^/assets/ {
                gzip_types text/plain application/x-javascript application/javascript text/css application/xml application/json;
                gzip_static on;
                expires max;
                add_header Cache-Control public;
              }

              try_files $uri/index.html $uri @puma;
              location @puma {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
                proxy_redirect off;

                proxy_pass http://puma;
              }

              error_page 500 502 503 504 /500.html;
              client_max_body_size 10M;
              keepalive_timeout 10;
            }
   }

更新:尽管无法使Nginx返回具有正确的mime类型的CSS,但我使用了一些客户端Javascript解决了该问题(从博客获得了针对另一个问题的修复)。这是我放入application.js中的代码。

    /* Fix for font awesome icons disappearing on reload*/
    document.addEventListener("turbolinks:before-render", function(event) {
      FontAwesome.dom.i2svg({
        node: event.data.newBody
      });
    });

0 个答案:

没有答案