微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Nginx – Rails中的WordPress博客使用mime类型的文本/ html加载样式和脚本

我刚刚在Rails应用程序的一个/博客目录下安装了一个wordpress博客,它运行在Unicorn和Nginx上,当我访问我的domain.com/blog页面时,我的样式表和脚本在浏览器中没有被正确加载. Chrome控制台给我以下错误

>资源解释为样式表,但使用MIME类型text / html进行传输
>资源被解释为脚本,但是使用MIME类型的文本/ HTML转移

一直在试图解决这个问题,在这里尝试了很多解决方案,但仍然无法通过…似乎需要改变我的Nginx配置,特别是对于博客/ PHP位置.这是我的配置:

upstream unicorn {
  server unix:/tmp/unicorn.domain.sock fail_timeout=0;
}

server {
  server_name www.domain.com;
  return 301 $scheme://domain.com$request_uri;
}

server {
  listen 80 default deferred;
  server_name domain.com;
  root /home/dcs/htdocs/domain/current/public;

  access_log /home/dcs/htdocs/domain/log/access.log;
  error_log  /home/dcs/htdocs/domain/log/error.log;


  location /blog {
    try_files $uri $uri/ /blog/index.PHP?$args;
  }

  location ~ \.PHP${
    fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
    fastcgi_pass unix:/var/run/PHP-fpm.sock;

    fastcgi_index index.PHP;
    fastcgi_param  SCRIPT_FILENAME home/dcs/htdocs/domain/$fastcgi_script_name;
    include /etc/Nginx/fastcgi_params;
  }


  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-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  keepalive_timeout 10;
}
确保您的Nginx配置中定义了一个类型指令.
Syntax:     types { ... }
Default:    

types {
    text/html  html;
    image/gif  gif;
    image/jpeg jpg;
}

Context:    http,server,location

将MIME类型的文件扩展名映射到响应.扩展名不区分大小写.几个扩展可以映射到一个类型,例如:

types {
    text/css                     css;
    application/javascript       js;
    application/json             json;
}

资料来源:http://nginx.org/en/docs/http/ngx_http_core_module.html#types

原文地址:https://www.jb51.cc/php/132529.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐