AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 436481
Accepted
a coder
a coder
Asked: 2012-10-10 07:52:54 +0800 CST2012-10-10 07:52:54 +0800 CST 2012-10-10 07:52:54 +0800 CST

不正确的 MIME 类型 - 拉扯我的头发

  • 772

我遇到 Apache 错误标记 text/html 的 CSS 文件的问题。文件类型在浏览器中不匹配,被忽略导致显示失败。

我在 RHEL 5 服务器上使用 Apache 2.2.3。

我尝试将其添加到httpd.conf并重新加载配置service httpd reload:

AddType text/css .css

浏览器看到的没有变化。我的 css 文件仍在显示text/html(即使当我使用 php curl 来探测 mime 类型时。这没有区别,服务器正在发送text/html文件)

然后,我注释掉了 中的以下几行httpd.conf,以确保魔术不会发生一些古怪的事情:

LoadModule mime_magic_module modules/mod_mime_magic.so

<IfModule mod_mime_magic.c>
  MIMEMagicFile /usr/share/magic.mime
  MIMEMagicFile conf/magic
</IfModule>

一旦这些被搁置,我保存并重新加载配置。没变。.css 文件仍然以text/html.

虚拟主机标准配置:

<VirtualHost 1.2.3.4:80>
    ServerName my.site.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/mysite/
    # Log info redacted #
</VirtualHost>

虚拟主机 SSL 配置:

<VirtualHost 1.2.3.4:443>

        ServerName my.site.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/mysite/

        # Log info redacted #
        # SSL Certificate config redacted #

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
            SSLOptions +StdEnvVars
        </Files>

        SetEnvIf User-Agent ".*MSIE.*" \
                 nokeepalive ssl-unclean-shutdown \
                 downgrade-1.0 force-response-1.0

        CustomLog logs/ssl_request_log \
                  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

这是我从 shell 得到的:

[boxor]# file --mime install.css
install.css: text/x-c; charset=us-ascii

这是我从 php 得到的:

$file = 'https://my.site.com/traq/install/install.css';
echo mime_content_type($file);

$file = $_SERVER['DOCUMENT_ROOT] . '/traq/install/install.css';
echo mime_content_type($file);

回报:

text/html; charset=UTF-8

text/plain

这三点都错了。

这是我的 apache 访问日志中的一行(添加了 Content-type):

1.2.3.4 - - [10/Oct/2012:08:32:38 -0400] "GET /traq/install//install.css HTTP/1.1" 200 2600 "http://my.site.com/traq/install/" "text/html" "Mozilla/5.0 blahblah Firefox/15.0.1"

同一页面中包含的不存在的 css 文件也作为“text/html”返回:

1.2.3.4 - - [10/Oct/2012:09:11:11 -0400] "GET /traq/install/idontexist.css HTTP/1.1" 200 2600 "http://my.site.com/traq/install/" "text/html" "Mozilla/5.0 blahblah Firefox/15.0.1"

所以...我在这里忽略了什么?

apache-2.2
  • 1 1 个回答
  • 4368 Views

1 个回答

  • Voted
  1. Best Answer
    a coder
    2012-10-11T05:31:36+08:002012-10-11T05:31:36+08:00

    我终于发现了问题。Traq安装视图文件 install/views/layout.php 在此文件的顶部包含一个文档类型:

    <!doctype html>
    <html lang="en" dir="ltr">
        <head>
            <title>Traq Installation<?php echo isset($title) ? " / {$title}" :''; ?></title>
    
            <style type='text/css'>
                @import '/traq/install/install.css';
                @import '/traq/install/test.css';
            </style>
    
    
        </head>
        <body>
            <div id="wrapper">
                <header id="head">
                    <h1>Traq Installation</h1>
                    <h2><?php echo isset($title) ? $title :''; ?></h2>
                </header>
                <div id="page">
                    <?php echo $output; ?>
                </div>
                <footer>
                    Traq &copy; 2009-<?php echo date("Y"); ?> Traq.io
                </footer>
            </div>
        </body>
    </html>
    

    删除顶线<!doctype html>解决了这个问题。包含的 css 文件现在被视为实际的 css 文件,样式终于出现了。

    • 2

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve