// you’re reading...

Tips N Tricks

Solved: Images load up partially when served by Apache Web Server

This was a very strange issue which showed up at one of my client’s Web application. The application is hosted on a Apache Web server and serves JPEG images. These JPEG files reside on a different server and mounted via CIFS (loosely called Samba mount) on the Linux machine running the Web server.

Now the issue was, many JPEG images, especially the larger ones, loaded up only partially in a Web browser (both Internet Explorer and Firefox). What made them load fully was pressing CTRL+R or clicking on Refresh/Reload several times. Bandwidth wasn’t an issue here, since this problem occurred even when browsing the JPEGs from the local network.

At first, I doubted that it could be an issue with the way the JPEGs are produced, something related to the progressive rendering et al. But then I came across an instance (too involved to explain it here) which proved me wrong.

Testing the case further, I found that the JPEGs load absolutely fine in the Web browser, when opened up via File>Open – instead of hitting the Web Server. This made me turn my eyes onto the Apache Web server. Googling around and reading the comments in the Apache configuration file gave a few hints. With some hit-n-trial, the solution that worked for me is as follows:

  • Login as root
  • Open the httpd.conf file (the configuration file of Apache Web server) in a text editor (like vi). On RedHat/Fedora/CentOS Linux, this file can be found in the directory /etc/httpd/conf
  • Append the following line to the end of the file:
    EnableSendfile off
    
  • Save the file.
  • Reload or restart the web server. On a RedHat/Fedora/CentOS Linux the command ‘service httpd reload’ can be used for the same.

The EnableSendFile directive in Apache is documented as: “Control whether the sendfile kernel support is used to deliver files (assuming that the OS supports it). The default is on; turn this off if you serve from NFS-mounted filesystems.”

What caught my attention was “turn this off if you serve from NFS-mounted filesystems”. But, in my case, the JPEG files were mounted via CIFS and not NFS. But reading more about the EnableSendFile directive at http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile, reveals the it affects even SMB (and hence CIFS) or any other network mounted files. Following is the snippet from the document:

With a network-mounted DocumentRoot (e.g., NFS or SMB), the kernel may be unable to serve the network file through its own cache.

Also, I guess, this solution is not specific to JPEG files. The above mentioned issue and the solution should be applicable to other file types too, which are served from a network mounted drive.

GD Star Rating
loading...
GD Star Rating
loading...
Solved: Images load up partially when served by Apache Web Server, 10.0 out of 10 based on 4 ratings
Share

Email This Post Email This Post Print This Post Print This Post Print This Post Post A Comment Tweet your comments/question to me @shekharg

Discussion

2 comments for “Solved: Images load up partially when served by Apache Web Server”

  1. This fixed my problem with apache only serving partial images! Thank you. Do you know if this setting effect XSendFile settings if XSendFile is installed?

    GD Star Rating
    loading...

    Posted by Robb Lovell | September 2, 2010, 5:31 am
  2. Hi Robb,

    Sorry for the delay in responding. I think you will still set EnableSendFile to off if the file that you are trying to stream is NFS/CIFS mounted

    GD Star Rating
    loading...

    Posted by Shekhar | September 7, 2010, 10:49 am

Post a comment