nginx在更改时提供错误的js文件

nginx serves wrong the js files on change

本文关键字:错误 js 文件 nginx      更新时间:2023-09-26

我有一个虚拟机(用puPHPet和流浪者构建)。当我更改.js文件时,Web服务器会错误地为其提供服务。

这是我的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个字符时,浏览器将在文件的末尾显示以下内容:

��

我用十六进制检查了一下。

EF BF BD EF BF BD

如果我删除文件中的任何位置,它将从浏览器中的文件末尾删除。我尝试了不同的浏览器,结果一直都是一样的。

我将nginx与php-fpm结合使用。如果我重新启动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;
    }
}

请帮助查找问题。

我遇到了同样的问题。。。

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

    server {
        ... ... ...
        ... ... ...
        location / {
                ... ... ...
                ... ... ...
        }
        location ~ '.php$ {
          ... ... ...
          ... ... ...
        }
        sendfile off;
    }