0

NGINX does not serve my images (with extension .jpg or .png) but it serves any other file (e.g. .txt, no extenstion at all).

This is the relevant part in my NGINX-Config:

location /uploads/ {
    alias /var/www/uploads/;
    autoindex on;
}

When I make a get request to https://myserver.com/uploads/ I get the following listing:

Listing

Clicking on test.txt works as expected, but for test.jpg or test.png I receive a 404 Error:

Error for images

Why's that and how to resolve the error?

Philip F.
  • 1,167
  • 1
  • 18
  • 33
  • You need to look at all of your other `location` blocks. Maybe you have one that matches URLs that end with `.jpg` or `.png`? – Richard Smith Mar 17 '23 at 10:30

1 Answers1

0

Have you checked the file permissions? Maybe image files have different permissions, in that case you can try to set the permissions as the other txt file.

You can try even to add the types directive in your nginx configuration. Here's an example:

types {
    image/jpeg             jpg;
    image/png              png;
}

server {
    listen 80;
    server_name example.com;
    root /var/www/html;

    location /uploads/ {
        alias /var/www/uploads/;
        autoindex on;
    }
}
Vez Figo
  • 28
  • 3