zoukankan      html  css  js  c++  java
  • 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 阶段的下一个模块。

  • 相关阅读:
    【xinsir】githook之precommit分享
    node进程一些信号的意义
    ES6篇
    Webpack4篇
    Node篇
    Vuex篇
    WebStorage篇
    HTML5篇
    html5语义化标签大全
    emmet语法
  • 原文地址:https://www.cnblogs.com/BlueFire-py/p/9037080.html
Copyright © 2011-2022 走看看