2

Apache 2.4/ PHP 7.0

Virtual hosts setup working correctly. There are no issues loading JPG files when pointing directly to the server using IP address.

<VirtualHost *:80>
  ServerName example.com 
  DocumentRoot /var/www/html/vhosts/example.com
  <Directory /var/www/html/vhosts/example.com>
    Require all granted
    <FilesMatch ".+\.(gif|jpe?g|png)$">
      Require all granted
    </FilesMatch>
  </Directory>
</VirtualHost>

However the images do not load when pointing to the hostname (example.com).

http://example.com/friendly.jpg Response:

Content-Type: text/html 503 Service Unavailable

As a workaround, I created a PHP symlink to the friendly.jpg

mynewphpfile.php -> friendly.jpg

http://example.com/mynewphpfile.php returns 200 successfully and displays friendly.jpg

Can you help resolve this issue?

Additional Steps
Modified /etc/hosts pointing example.com to IP

Executing from local www server:
curl --head http://example.com/friendly.jpg
Returns: 200 OK successfully (correct image content-length in bytes shown)
Content-Type: image/jpeg

curl -v http://example.com/friendly.jpg
Returns: 200 OK successfully (correct image content-length in bytes shown)
Content-Type: image/jpeg


Executing from external machine:
curl --head http://example.com/friendly.jpg
Returns: 200 OK successfully (correct image content-length in bytes shown)
Content-Type: image/jpeg

curl -v http://example.com/friendly.jpg
Returns: 503 Service unavailable
Content-Type: text/html

8
  • Have you tried removing the filesmatch directive? You will need to restart Apache to test. Also, it seems that your directory directive is not closed properly. Needs a slash. Outside of these two things, I do not see anything right off. Cheers!!
    – closetnoc
    Commented Apr 21, 2018 at 1:25
  • Yes I've tried both suggestions, but unfortunately it still doesn't work even without FilesMatch. This behavior seems very strange. In addition, the 503 errors do not appear in the logs and neither does the GET request for anything besides PHP files. Btw, the instance is running on AWS. Commented Apr 21, 2018 at 1:48
  • Okay. I am stumped! I will have to think on this. BTW- I use Apache. Not sure what differences there are between Apache and AWS if any.
    – closetnoc
    Commented Apr 21, 2018 at 3:19
  • 1
    Are you using a load balancer, firewall, or a reverse proxy? Since the requests are not appearing in the log file I suspect something is filtering them before they get to your server. Elastic load balancers use 503. Use curl --head http://example.com/friendly.jpg both from the server itself and from an external machine. See if there are differences. Check for an X-Powered-By header. Set the hostname and IP address in /etc/hosts and try again making sure DNS is pointing directly to the server and not through some intermediary. Edit your question and add the findings from those. Commented Apr 21, 2018 at 9:58
  • 1
    Thanks guys. Stephen, I think there may be some intermediary. When executing a PHP file with $_REQUEST to see the headers, I noticed NetScaler shown along with Apache/PHP. However, I never set this up nor do I see it installed on my machine. Commented Apr 22, 2018 at 2:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.