【发布时间】: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