Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location and document path in nginx

Tags:

nginx

This is my nginx configuration file:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   d:/www;
        index  index.html index.htm;
    }
    location /js/api/ {
        root   D:/workspace/javascript/maplib/;
        autoindex on;
    }
}

And the directory of the document is like this:

D:/workspace/javascript/maplib
    -- v1.0
         --main.js
    -- v1.1

Now I want to access the v1.0/main.js by http://localhost/js/api/v1.0/main.js.

And it returns a 404 error.

It seems that ngnix will tried to get the file through D:/workspace/javascript/maplib/js/api/v1.0/main.js which does not exist.

It seems that the string path in the location(in the url) must exist at the file system.

How to fix it to meet my requirement?

BTW, there is not only the js but also some other kinds of files like .gif,.png,.html inside the D:/workspace/javascript/maplib/.

like image 330
hguser Avatar asked May 13 '13 01:05

hguser


1 Answers

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

That is, replace

root   D:/workspace/javascript/maplib/;

by

alias   D:/workspace/javascript/maplib/;
like image 66
Chuan Ma Avatar answered Oct 23 '22 00:10

Chuan Ma