firefox和chrome都显示我的服务器的javascript文件是作为MIMEtypestext / html提供的。 JavaScript文件具有.js扩展名。
首先,mime_module已安装并处于活动状态:
apachectl -M | grep mime mime_magic_module (shared) mime_module (shared) Syntax OK
其次,我在我的conf文件中有这个:
AddType text/css .css AddType text/javascript .js
我试着添加这个:
<Files "*.js"> ForceType text/javascript </Files>
并重新启动apache,但JavaScript文件在Chrome和Firefox仍然显示为“text / html”。 没有显示error.log和access.log没有返回任何有用的东西:
1.2.3.4 - - [03/Mar/2015:10:42:00 -0500] "GET /some/dir/js/app-min.js HTTP/1.1" 200 14642
这里是其中一个.js文件的标题(如Firefox中所示)
Connection: close Content-Type: text/html; charset=UTF-8 Server: Apache Strict-Transport-Security: max-age=63072000; includeSubDomains Transfer-Encoding: chunked X-Content-Type-Options: nosniff X-Frame-Options: DENY X-Permitted-Cross-Domain-Policies: master-only X-WebKit-CSP: default-src 'self' X-XSS-Protection: 1; mode=block
该文件在Firefox检查器中显示为typeshtml 。
这里是我的笔记本电脑的apache实例提供的相同文件的标题:
Connection: Keep-Alive Date: Tue, 03 Mar 2015 15:43:52 GMT Keep-Alive: timeout=5, max=95 Server: Apache/2.4.7 (Ubuntu)
该文件在Firefox检查器中显示为typesjs 。 请注意,Apache(2.4)的本地实例未响应Content-Type 。
为什么主服务器违反了AddType? 我已经添加到httpd.conf和ssl.conf(虽然我的网站力量443)。 我已经重新启动apache(没有语法错误)。
我有一个smilimar问题,一些系统pipe理员添加下一个指令con conf.modules.d / 10-php.conf:
SetHandler application/x-httpd-php
但是,这一切都是为了让所有人感到放松,所以我改变了:
AddHandler php5-script .php
问题解决了:)
问题解决了。 conf.d / php.conf包含这些行:
AddHandler php5-script .php .phtml .html .css .js AddType text/html .php
我把第一行改成了
AddHandler php5-script .php .phtml .html AddType text/html .php
然后保存并重新启动Apache。 现在,js&css文件在Firefox / Chrome中显示为正确的MIMEtypes。
另外,我尝试在AddType text/html .php下面添加AddType text/javascript .js ,但是文件在Inspector中仍然显示为text/html 。 我必须从AddHandler中删除.css和.js才能发送正确的MIMEtypes。