vagrant 中的 JS 和 CSS 文件在 VM 之外保存时未正确编码 [英] JS and CSS files in vagrant not properly encoded when saved outside of the VM

查看:17
本文介绍了vagrant 中的 JS 和 CSS 文件在 VM 之外保存时未正确编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OSX、Ubuntu 和 Windows 7 上运行 vagrant,并在主机上使用 vim 和 Netbeans 作为 IDE.虚拟机运行 CentOS 6.3 和 Apache 2.2.docroot 设置为 /vagrant.

I'm running vagrant on OSX, Ubuntu, and Windows 7 and using vim and Netbeans as IDEs on the host machine. The VM is running CentOS 6.3 and Apache 2.2. The docroot is set to /vagrant.

当我编辑一个 JS 或 CSS 文件并保存它时,浏览器会转过身来检测非法字符.当我在浏览器中查看文件时,我看到菱形问号字符,这通常表示编码问题.我可以在虚拟机的 vim 中打开文件并用 :w ++enc=utf-8 保存,文件将正常加载.

When I edit a JS or CSS file and save it, the browser then turns around and detects illegal characters. When I view the file in the browser I see the diamond-question mark character which usually points to an encoding issue. I can open the file up in vim inside the VM and save it with :w ++enc=utf-8 and the file will load normally.

我已经在主机和不同的主机操作系统上尝试了多个 IDE,并且只能将其与 vagrant 和挂载目录有关.我的 IDE 不是问题,因为我可以在本地运行文件并且它们可以工作,或者将它们保存到远程机器并且文件可以工作.只有当我将它们保存到安装在 /vagrant 中的东西时,我才会遇到问题.

I've tried multiple IDEs on the host machine and different host OSes, and can only pinpoint it to something to do with vagrant and the mounted directory. My IDEs aren't the problem as I can run the files locally and they work, or save them to a remote machine and the files work. Only when I save them to what gets mounted in /vagrant do I have a problem.

我需要更改 Apache 还是操作系统中的其他东西才能使其正常工作?

Is it Apache or something else in the OS that I need to change to get this to work?

推荐答案

我今天早上遇到了这个问题.在 httpd.conf 中将 EnableSendfile 设置为关闭.

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

如果您查看您的 httpd.conf,它会显示如果您从 NFS 挂载的文件系统提供服务,请关闭它".在 http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile 它解释说:默认情况下,当处理请求不需要访问文件中的数据时——例如,在交付静态文件时——Apache 使用 sendfile 来交付文件内容而无需读取如果操作系统支持文件."

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."

因为你的 windows 主机有一个 ntfs 文件系统,linux 来宾没有用 sendfile 正确缓存文件,所以 apache 需要自己发送文件.从 apache 请求文件时,这可能会导致轻微的减速,但应该可以忽略不计.

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.

这篇关于vagrant 中的 JS 和 CSS 文件在 VM 之外保存时未正确编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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