加入收藏 | 设为首页 | 会员中心 | 我要投稿 商洛站长网 (https://www.0914zz.com/)- AI应用、CDN、边缘计算、云计算、物联网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2023-12-12 16:35:28 所属栏目:Nginx 来源:DaWei
导读: 我刚刚在Rails应用程序的一个/博客目录下安装了一个Wordpress博客,它运行在Unicorn和Nginx上,当我访问我的domain.com/blog页面时,我的样式表和脚本在浏览器中没有被正确加载. Chrome控制台给

我刚刚在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

(编辑:商洛站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章