【问题标题】:nginx serves wrong the js files on changenginx 在更改时提供错误的 js 文件
【发布时间】:2016-02-12 08:02:49
【问题描述】:

我有一个虚拟机(用 puPHPet 和 vagrant 构建)。 当我更改 .js 文件时,网络服务器会错误地提供它。

这是我的 js 文件的结尾:

    $(document).ready(function () {
        // $('.chat-menu-toggle').sidr({
        //     name: 'sidr',
        //     side: 'right',
        //     onOpen: function () {
        //         PslConversation.sidebarOpen = true;
        //     },
        //     onClose: function () {
        //         PslConversation.sidebarOpen = false;
        //     }
        // });
        PslConversation.init();
        window.PslConversation = PslConversation;
    });
});

当在文件的任何地方添加 3 个字符时,在浏览器中会在文件的 END 处得到这个:

��

我用十六进制检查了它。

EF BF BD EF BF BD

如果我删除文件中的任何位置,它将从浏览器中的文件末尾删除。 我尝试了不同的浏览器,结果始终相同。

我正在使用带有 php-fpm 的 nginx。如果我重新启动 nginx 没有任何变化,但是当我更改 php 文件时没有问题,只有在 js 和 css 中。

据我所知,我没有任何缓存。

我的 nginx 配置:

server {
    listen  192.168.56.102:80;

    keepalive_timeout   70;

    listen   80;

    set $host_path "/var/www/html";

    server_name frontend.psl;
    root   $host_path/frontend/web;
    set $yii_bootstrap "index.php";

    charset utf-8;

    location / {
        index  index.html $yii_bootstrap;
        try_files $uri $uri/ /$yii_bootstrap?$args;
    add_header Access-Control-Allow-Origin *;
    }

    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
    fastcgi_read_timeout 150;
        #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

请帮忙找出问题。

【问题讨论】:

  • 您使用的是哪个文本编辑器? EF BF BD 是Unicode Replacement Character,如果文本编辑器错误地解释文件的字符编码并试图将其打开为 utf-8,就会发生这种情况。
  • 我正在通过共享目录使用 sublime text 3。但是如果我用 mcedit 在服务器上编辑文件,结果是一样的。
  • 试用EncodingHelper 插件来检查您的文件使用的字符编码(如果需要,将其转换为utf-8!)

标签: javascript caching nginx


【解决方案1】:

我有同样的问题...

在 nginx 配置文件末尾添加这一行 sendfile off; 应该可以修复它

喜欢

    server {
        ... ... ...
        ... ... ...
        location / {
                ... ... ...
                ... ... ...
        }

        location ~ \.php$ {
          ... ... ...
          ... ... ...
        }

        sendfile off;

    }

【讨论】:

  • 这对我有用。之后不要忘记重新启动您的 nginx 服务器。例如,在 Ubuntu 上使用 sudo service nginx restart
猜你喜欢
  • 2011-04-25
  • 2021-01-31
  • 2015-03-13
  • 2017-05-10
  • 1970-01-01
  • 1970-01-01
  • 2013-04-04
  • 2019-02-18
  • 1970-01-01
相关资源
最近更新 更多