logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache2 not serving images from network drive
Author
FixItDik



Joined: 30 Jun 2021
Posts: 3
Location: UK, Ipswich

PostPosted: Wed 30 Jun '21 13:07    Post subject: Apache2 not serving images from network drive Reply with quote

Background:
So I have a Raspberry Pi (RPI) 3b+ with Debian Buster freshly installed using the Raspberry Pi imager then updated and Apache2 version 2.4.38 installed (along with PHP and MySQL). All the latest stable versions (well, whatever the apt install gives me at the time).

This is a rebuild of a machine that was working fine but crashed without a backup when I was performing an update but was such a simple configuration it was no heartache to do - I thought...

I keep all my website software on a network share of a Windows machine which I have configured to mount automatically at boot of the RPI and it mounts to /mnt/websites

In my /var/www/html folder I have created (using the "sudo ln -s /mnt/websites/{subsite} {subsite}" command) soft links to the sub folders that I want Apache to host.

This worked fine before my crash serving everything as it should.

Problem
It works now for HTML (raw or PHP-generated), CSS, JavaScript and other text files, *HOWEVER* image files (GIFs, PNGs, JPGs) that the HTML refers to are delivered to the browser but appear corrupt either in themselves or in the header information sent to the browser (I am not wizz enough to determine the actual reason browsers will not show them).

To demonstrate this I have set up a test.html file on my server which references 4 images, 2 GIFs and 2 PNGs, one each of which is local (with the test.html in the /var/www/html/ folder) and the others are from a linked network folder.

Someone suggested setting "EnableSendFile On" in the <Directory /var/www/> section of apache2.conf - amazingly that seemed to work for some images and not others (and I cannot work out the difference between them).

I have checked the permissions on all the files (none of which have changed since I built this new setup) and all files & folders involved have read access for everyone - but if this were a permissions issue I would expect a 403 error for the images rather than this strange corrupt delivery.

See for yourself
So here is a link to my test.html, it has 4 images with only the local ones working at the moment:

{{URL removed as solution found}}

Suggestions please!

Thanks

Dik


Last edited by FixItDik on Wed 30 Jun '21 15:03; edited 1 time in total
Back to top
FixItDik



Joined: 30 Jun 2021
Posts: 3
Location: UK, Ipswich

PostPosted: Wed 30 Jun '21 13:15    Post subject: Reply with quote

Update:
It appears that the browser is timing out waiting for the image file from Apache after 5 seconds (I am looking at dev tools in Chrome to see this happen on the network tab)

Also, if you right-click on the broken image and select 'open in new tab' you actually get a file downloaded with the right name but is clearly not a gif image, so what is Apache sending to the browser to save in the file? I opened the file in a binary editor and found this:

Code:
pache/2.4.38 (Raspbian)
Last-Modified: Wed, 20 Jan 2021 11:27:33 GMT
ETag: "7d-5b9533dc657b7"
Accept-Ranges: bytes
Content-Length: 125
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/gif

GIF89
{followed by binary}

It's like the header information is being sent as the file content? As this is the same behaviour on all browsers I have tried (FF did not save the downloaded image but complained it "contains errors" and IE tried to display the file to me as text, pretty much as you see above) I think this is Apache not the browsers?
Back to top
FixItDik



Joined: 30 Jun 2021
Posts: 3
Location: UK, Ipswich

PostPosted: Wed 30 Jun '21 15:02    Post subject: Reply with quote

Sorry - found my own solution, although I have to say I am not impressed by the outcome of not doing this: Setting "EnableMMap Off" in the <Directory /var/www/> section of apache2.conf and then restarting Apache means it is now working. If anyone can explain the behaviour I was seeing without this setting I would be grateful to know.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Thu 01 Jul '21 9:57    Post subject: Reply with quote

From the docs[1]
Quote:

This directive controls whether the HTTPd may use memory-mapping if it needs to read the contents of a file during delivery. By default, when the handling of a request requires access to the data within a file -- for example when delivering a server-parsed file using mod_include -- Apache HTTPd memory-maps the file if the OS supports it.


In other words, apache "stores" the file content within the memory and does not read it from the file system. From network shares that is never a good option. The docs recommend turning it off for that.

if you still have a question please ask again.

[1] https://httpd.apache.org/docs/2.4/en/mod/core.html#enablemmap
Back to top


Reply to topic   Topic: Apache2 not serving images from network drive View previous topic :: View next topic
Post new topic   Forum Index -> Apache