Nginx02---指令集实现静态文件服务器

location

实现静态服务器,就是root和alias命令,他们位于location文件块中,详细:https://www.jianshu.com/p/4be0d5882ec5

 

root

root后跟的指定目录是上级目录,并且该上级目录下要含有和location后指定名称的同名目录才行,末尾“/”加不加无所谓。

location /c/ { 
      root /a/
}

如果访问站点http://location/c访问的就是/a/c目录下的站点信息。

 

allias

alias后跟的指定目录是准确的,并且末尾必须加“/”,否则找不到文件

location /c/ { 

      alias /a/
}

如果访问站点http://location/c访问的就是/a/目录下的站点信息。

 

 

写绝对路径

root 指令

location /dir/ 
root root_path         ->  http://host/dir/file.txt  -> root_path/dir/file.txt

alias 指令

location /dir
alias alias_path       ->  http://host /dir /file.txt  -> alias_path/file.txt

location /dir/ 
alias alias_path/      ->  http://host /dir/ file.txt  -> alias_path/file.txt


index页面配置

#设置虚拟主机默认访问的网页

location / {
root /var/www/;
index index.htm index.html;
}

这样,当用户请求 / 地址时,Nginx 就会自动在 root 配置指令指定的文件系统目录下依次寻找 index.htm 和index.html 这两个文件。如果 index.htm 文件存在,则直接发起“内部跳转”到 /index.htm 这个新的地址;而如果 index.htm 文件不存在,则继续检查 index.html 是否存在。如果存在,同样发起“内部跳转”到/index.html;如果 index.html 文件仍然不存在,则放弃处理权给 content 阶段的下一个模块。

posted @ 2018-05-14 17:15  Gaoyongxian666  阅读(173)  评论(0编辑  收藏  举报