nginx config to serve static files

Dear all,

I currently have setupped my nginx to be able to serve static files. The snippets is as such:

server {
        listen   80;
        server_name  72.14.185.215;

        location / {
                root   /var/www/nginx-default;
                index  index.html index.htm;
        }

        location /media {
                root /var/www/media;
#               autoindex on;
#               allow all;
        }
}

Now when I access from the browser using this address http://72.14.185.215/media , I get a 404 message. I already created the /var/www/media folder. Have I missed on something here?

Thanks in advance

2 Replies

did you try switching the two location statements and putting "/media" first ?

chances are the "/" location is used first, it evaluates to

"/var/www/nginx-default" + "media" –> "/var/www/nginx-default/media" (which doesn't exist i assume)

and returns the 404

It's also redirecting to http://localhost/media/

Just pointing that out. :\

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct