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 - Broken images load from remote server
Author
yanover



Joined: 08 Jun 2020
Posts: 4
Location: Switzerland

PostPosted: Mon 08 Jun '20 21:08    Post subject: Apache2 - Broken images load from remote server Reply with quote

I have an apache2 server running under Ubuntu 18.04

Strangely, apache cannot display images, event though my browser load it with a 200 response message. If I trigger directly the image link, I can download it successfully, but the image cannot be open (wrong format), like it is broken.

This website used to work on another apache2 with approximately the same configuration.

I have tried to put an image file into the default folder (var/www) and display it with a simple src, it works !

My website that refuses to display images has this configuration in apache2.conf :

Code:
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

And the virtualhost looks like this :

Code:
<VirtualHost *:80>
ServerName nasticot.lan
DocumentRoot /var/www/nasticot.lan
ServerAlias www.nasticot.lan
</VirtualHost>


/var/www is an SMB share mounted from a remote container.
The server has full rights on every file into this share (777)

There is also an .htaccess file at the root of the website

Code:
# Rewrite URL like xxx/yyy/zzz in index.php?controleur=xxx&action=yyy&id=zzz
RewriteEngine on
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controleur=$1&action=$2&id=$3 [NC,L]


strangely, apache2 add content to my images on load.

I've verified one more time that my images are displayable directly in the folder read by my apache2 server, and it works.

If I download the image locally from the browser, the image has a few more line added to it.

My /var/www is a mounted share, located in my fileserver.

I found that this is the problem. If I copy the content of one of my website locally, images are displayed.

Event though I've full access to the mounted share :

root@coruscant:/var/www/nasticot.lan/Content/img/icon# ls -la /var/www
total 4
drwxrwxrwx 2 root www-data 0 Mar 20 15:54 .
drwxr-xr-x 14 root root 4096 Mar 20 19:31 ..
drwxrwxrwx 2 root www-data 0 Mar 24 11:08 nasticot.lan

And this is the share configuration in the fileserver :

Code:
[WWW]
path = /media/share/www
browseable = yes
writeable = yes
read only = no
force create mode = 0770
force directory mode = 2770
valid users = @sambashare


And finally, the fstab file on the webserver :

Code:
//192.168.0.53/WWW /var/www cifs credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777,gid=www-data 0 0


Images file are loaded (200 OK) but broken ..

really know where to search anymore ..

Please any help would be very appreciated


Any idea ?

Thank you !
Back to top
James Blond
Moderator


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

PostPosted: Mon 08 Jun '20 23:26    Post subject: Reply with quote

what lines are inserted into the images via apache?
Back to top
yanover



Joined: 08 Jun 2020
Posts: 4
Location: Switzerland

PostPosted: Tue 09 Jun '20 9:52    Post subject: Reply with quote

Thanks for your answer,

With an image it inserts unreadable characters. I have an angular application which runs into this apache container, if I host it locally it works as expected, but if the document root is located into the mounted share, il failed.

My Angular application uses a JSON file to load throw http a JSON file with configuration values, the behavior is the same and I can show you what the json file looks like after being loaded by the server

File into the mounted share

Code:
{
    "server": "http://labo.nasticot.lan/recette.rest",
    "uri": "/resources",
    "port": "80"
}


File into the text bloc of the http error response after load

Code:
" 09:38:42 GMT
ETag: "68-5a78f605c2c5b"
Accept-Ranges: bytes
Content-Length: 104
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/json

{
    "server": "http://labo.nasticot.lan/recette.rest",
    "uri": "/resources",
    "port": "80"
}��'`Q�N�s��r����������������g�� �VH�7��l[<��k�4�&8��VZik&I�6��9L|�� ����"


Hope it helps.

Yanover
Back to top
James Blond
Moderator


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

PostPosted: Tue 09 Jun '20 12:03    Post subject: Reply with quote

The first few files are okay, but

Code:

Content-Type: application/json

{
    "server": "http://labo.nasticot.lan/recette.rest",
    "uri": "/resources",
    "port": "80"
}


is wrong. The content type should be like image/jpeg or mage/png

I think, you should exclude images from the rewriting to index.php in the htaccess

RewriteRule ^(dir_name|file_name\.extension|and_so_on) - [L]

e.g.
Code:

RewriteEngine on
RewriteRule ^(content_images|design_images|css|js|media|lib|index\.php) - [L]
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controleur=$1&action=$2&id=$3 [NC,L]


[code]
Back to top
yanover



Joined: 08 Jun 2020
Posts: 4
Location: Switzerland

PostPosted: Tue 09 Jun '20 16:05    Post subject: Reply with quote

Thanks for your support.

In my last message, I was just showing an example with my angular application, and the file which is being loaded is indeed a json file, so the content type application/json is correct I guess .. I made this message to show you that the problem is not only with images.

I did a lab in my network :

My server apache has now two different virtualhosts for the same website.

One of the documentRoot is located in the mounted share.
The other is locally into /var/www

As expected, the local website can display images and the other can not.

As you talked about content/type, I found that there's in fact a problem at this level.

All the images retrieve by the broken website are of type "octet-stream" while on the other it is "jpeg".

However, it still affects a simple json file of type "application/json" so I'm not sure it explains everything ..

I tried to add the line you propose, but it did not change anything and I wouldn't work on both instances (local/share) if the .htaccess wasn't well written, right ?

Thank you again for your support !

Yanover
Back to top
yanover



Joined: 08 Jun 2020
Posts: 4
Location: Switzerland

PostPosted: Tue 09 Jun '20 16:36    Post subject: Reply with quote

After hours of research i found a workaround !

It is an apache2.4 bug that make content-type corrupt if EnableSendfile is not set to ON !

This only happens when serving the files from samba !

Here is my apache2.conf for the shared directory

Code:
<Directory /media/share/www/>
        EnableSendfile On
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride None
        Require all granted
</Directory>

Sorry for the post
Back to top


Reply to topic   Topic: Apache2 - Broken images load from remote server View previous topic :: View next topic
Post new topic   Forum Index -> Apache