NGINX does not serve images

749 Views Asked by At

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?

1

There are 1 best solutions below

0
Vez Figo On

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;
    }
}