Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Root directory shows 404 in nginx

Tags:

nginx

I am new to nginx server. I tried to set a new url "/images/" for serving images. I edited the bi.site file in site-enabled folder.

server {
   listen *:80;
   access_log /var/log/myproject/access_log;
    location / {
        proxy_pass         http://127.0.0.1:5000/;
        proxy_redirect     off;

        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
    location /images/ {
        root /www/myproject/files_storage;
    }

}

And in /www/myproject/files_storage location i put a temp.txt file.

When i put http://www.main_url/images/temp.txt it shows 404 not found. What am i doing wrong ? Did i miss something important ?

like image 537
nidhinpd Avatar asked Jan 21 '15 06:01

nidhinpd


1 Answers

this:

location /images/ {
        root /www/myproject/files_storage;
    }

results in /www/myproject/files_storage/images path, it would be obvious if you setup error_log. So use "alias" directive instead of "root"

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

like image 81
SuddenHead Avatar answered Nov 15 '22 10:11

SuddenHead