Nginx配置静态文件404问题解决

星期一, 2017-10-23 | Author: Lee | computer, linux | 3,832 views

Nginx提供了另外一个静态路径配置 : alias

alias与root区别

官方root

Sets the root directory for requests. For example, with the following configuration
location /i/ {
    root /data/w3;
}
The /data/w3/i/top.gif file will be sent in response to the “/i/top.gif” request

官方alias

Defines a replacement for the specified location. For example, with the following configuration
location /i/ {
    alias /data/w3/images/;
}
on request of “/i/top.gif, the file /data/w3/images/top.gif will be sent.

当访问/i/top.gif时,

root是去/data/w3/i/top.gif请求文件,

alias是去/data/w3/images/top.gif请求

root响应的路径:配置的路径+完整访问路径(完整的location配置路径+静态文件)

alias响应的路径:配置路径+静态文件(去除location中配置的路径)

修改配置为

location /api/v1/upload {  
     alias /home/v1/upload/;  
}

注意

使用alias时目录名后面一定要加“/”

一般情况下,在location /中配置root,在location /other中配置alias

Tags:

文章作者: Lee

本文地址: https://www.pomelolee.com/1769.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

文章分类

Links

Meta