Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS and CSS files in vagrant not properly encoded when saved outside of the VM

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.

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.

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.

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

like image 702
dragonmantank Avatar asked Oct 08 '12 13:10

dragonmantank


2 Answers

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.

like image 169
John McCombs Avatar answered Oct 01 '22 02:10

John McCombs


It depends on what server you are using.

For Nginx: in /etc/nginx/nginx.conf:

change the line that contains sendfile on; to sendfile off;.

For Apache: in /etc/httpd/conf/httpd.conf:

change remove comment for EnableSendfile off;

And don't forget restart your Nginx or Apache. If it still doesn't work, exit and vagrant reload or something like that - restart your VM.

like image 20
Bơ Loong A Nhứi Avatar answered Oct 01 '22 03:10

Bơ Loong A Nhứi