cleey
望着那一丝海线,若隐若现。落日下的海霞,数不尽的美,看不完的醉
vagrant 在本地编辑 js 和 css 后,vagrant nginx或 apache 读取的数据为乱码

这个不是 vagrant 本身的问题

归结于 sendfile 的优化和操作系统文件系统的差异。

解决方案:

nginx:

vim /etc/nginx.conf

http { 
  sendfile off;  # 之前为 on
}

apache:

vim /etc/http.conf

# 新增
EnableSendfile Off

#或者
<Directory "/path-to-nfs-files">
  EnableSendfile Off
</Directory>


具体问题描述

I had this problem this morning. Set EnableSendfile to off in your httpd.conf.

If you look at your httpd.conf it says "turn this off if you serve from NFS-mounted filesystems." In http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile it explains that "By default, when the handling of a request requires no access to the data within a file -- for example, when delivering a static file -- Apache uses sendfile to deliver the file contents without ever reading the file if the OS supports it."

Since your windows host has an ntfs file system, the linux guest doesn't properly cache the file with sendfile and so apache needs to send the file itself. This may cause a marginal slowdown when requesting files from apache, but it should be negligible.


参考:

https://stackoverflow.com/questions/12782946/js-and-css-files-in-vagrant-not-properly-encoded-when-saved-outside-of-the-vm

http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile

<< 上一篇 redis 高可用架构之 sentinel mongodb 权限管理,添加用户授权 下一篇 >>
文章标签
随意 | Created At 2014 By William Clinton | 蜀ICP备14002619号-4 |