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/
.
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/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With