alias指令
syntax: alias path;# 静态文件路径 alias不会将请求路径后的路径添加到 path中
context : location;
root指令
syntax : root path; #静态文件路径 root会将请求路径后添加的 path中
context : http,server,location,if in location
location /root { root html; } location /alias{ alias html; } location ~/root/(\w+\.txt){ root html/first/$1; } location ~/alias/(\w+\.txt){ alias html/first/$1; }
访问 http://xxxx/root 返回404 通过error日志 可以看到 会在html后加上root目录
访问 http://xxxx/alias 返回nginx主页面 返回正确
访问 http://xxxx/root/1.txt 返回404
访问 http://xxxx/alias/1.txt 则返回1.txt内容