【问题标题】:NGINX not loading external css fileNGINX不加载外部css文件
【发布时间】:2013-11-27 01:15:37
【问题描述】:

我创建了一个测试 html 页面,内联 javascript 和 css 工作正常。但是当引用外部 css 表时,它似乎没有加载。

/var/www/ME/test.html

    <html>
            <head>
                    <link href="/test.css" type="text/css" rel="stylesheet" />
            </head>

            <body onload="javascript:alert('test');">
                    <div class="test">
                            <h1>Hi my name is tzvi</h1>
                    </div>
            </body>
    </html>

/var/www/ME/test.css

    .test {
            color:"red";
    }

/etc/nginx/nginx.conf

    user www-data;
    worker_processes 4;
    pid /var/run/nginx.pid;

    events {
    worker_connections 768;
    # multi_accept on;
    }

    http {
    include /etc/nginx/mime.types;
    default_type text/html;

    server {
            listen   80; ## listen for ipv4; this line is default and implied
            listen   [::]:80 default ipv6only=on; ## listen for ipv6

            error_log /var/log/nginx/file.log warn;

            root /var/www/ME;
            index index.php;

            server_name localhost;

            location / {
                            include /etc/nginx/mime.types;
                            try_files $uri $uri/ /index.php;
                            error_log /var/log/nginx/test.log warn;
            }

            location ~ \.php$ {
                            fastcgi_split_path_info ^(.+\.php)(/.+)$;
                            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                            fastcgi_pass 127.0.0.1:9000;
                            fastcgi_index index.php;
                            include fastcgi_params;
            }
    }
    }

当我转到http://&lt;webserver&gt;/test.html 时,我得到了 javascript 弹出窗口和黑色文本。如果 css 可以工作,文本应该是红色的。

谢谢

【问题讨论】:

  • 有没有试过直接在浏览器中加载css url,看看文件下载是否正确?
  • @StephaneRolland 它加载 css 文件文本。它应该下载而不是显示吗?感谢您的回复
  • 如果它加载了css文件,那么当你加载html文件时,css很可能是可以访问的。只有在我看到 css 可能被阻止的情况下是跨域引用,即如果您的 css 文件来自另一台服务器。
  • 去掉css文件中颜色名称的双引号。

标签: html css nginx


【解决方案1】:

把css文件改成

  .test {
            color:red;
    }

您应该在 css 中指明颜色名称,不要将双引号 "" 括起来。

【讨论】:

    猜你喜欢
    • 2019-01-16
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 2016-02-09
    相关资源
    最近更新 更多