root 路径;
root指定的路径需要结合映射地址,例如:
location /static {
root /usr/share/nginx;
}
此时访问:http://ip/static/index.html
实际访问的路径为:/usr/share/nginx/static/index.html
alias 路径;
alias指定的路径不需要结合映射地址,例如:
location /static {
alias /usr/share/nginx/; //若路径为文件,则需要以/结尾
}
此时访问:http://ip/static/index.html
实际访问的路径为:/usr/share/nginx/index.html
路径匹配
=开头表示精确匹配
^~开头表示以某个字符串开头,不是正则匹配
~开头表示区分大小写的正则匹配
~* 开头表示不区分大小写的正则匹配
/表示通用匹配,如果没有其它匹配,则任何请求都会匹配到
路径匹配优先级:(location = )> (location 完整路径)> (location ^~ 路径)> (location ,* 正则顺序)> (location 部分起始路径)> (/)
index 空格分隔的文件名;
配置默认首页
autoindex off | on
配置是否允许目录浏览
proxy_pass
配置反向代理