我刚刚在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配置中定义了一个类型指令.
原文链接:https://www.f2er.com/php/132529.htmlSyntax: 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