NGINX 不加载外部 css 文件 [英] NGINX not loading external css file

查看:66
本文介绍了NGINX 不加载外部 css 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

/var/www/ME/test.html

 <头><link href="/test.css" type="text/css" rel="stylesheet"/><body onload="javascript:alert('test');"><div class="test"><h1>我叫 tzvi</h1>

</html>

/var/www/ME/test.css

 .test {红色";}

/etc/nginx/nginx.conf

 用户 www-data;worker_processes 4;pid/var/run/nginx.pid;事件{worker_connections 768;# multi_accept on;}http {包括/etc/nginx/mime.types;default_type 文本/html;服务器 {听80;##监听ipv4;这一行是默认的和隐含的听 [::]:80 默认 ipv6only=on;##监听ipv6error_log/var/log/nginx/file.log 警告;根/var/www/ME;索引 index.php;server_name 本地主机;地点/{包括/etc/nginx/mime.types;try_files $uri $uri//index.php;error_log/var/log/nginx/test.log 警告;}位置 ~ \.php$ {fastcgi_split_path_info ^(.+\.php)(/.+)$;# 注意:你应该有cgi.fix_pathinfo = 0;"在 php.inifastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;包括 fastcgi_params;}}}

当我转到 http://<webserver>/test.html 时,我看到了 javascript 弹出窗口和黑色文本.如果 css 可以正常工作,文本应该是红色的.

谢谢

解决方案

将css文件改为

 .test {红色;}

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

I created a test html page, inline javascript and css is working fine. But when an external css sheet is referenced, it doesn't seem to load.

/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;
            }
    }
    }

When I go to http://<webserver>/test.html I get the javascript popup, and the text in black. If the css would be working, the text should be red.

Thanks

解决方案

change the css file to

  .test {
            color:red;
    }

you should indicate the color name in the css without surrounding doubles quotes "".

这篇关于NGINX 不加载外部 css 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆