美文网首页
NGINX----应用----root和alias

NGINX----应用----root和alias

作者: JuMinggniMuJ | 来源:发表于2020-05-24 12:40 被阅读0次

    nginx指定文件路径有两种方式root和alias.这两者有什么区别?

    1.准备测试目录和文件:

    在html文件夹下创建两个文件夹root和alias:

    cd /usr/local/nginx/html;      #切换到html目录
    mkdir root alias;              #创建root和alias两个文件夹
    chmod -R 777 root alias;       #设置权限777
    

    分别在root和alias文件夹下创建index.html

    touch /usr/local/nginx/html/root/index.html
    echo 'this is root test' > /usr/local/nginx/html/root/index.html
    touch /usr/local/nginx/html/alias/index.html
    echo 'this is alias test' > /usr/local/nginx/html/alias/index.html
    
    2.测试root:

    修改配置文件:

     location /root{
            root /usr/local/nginx/html/;
            index index.html;
    }
    
    3.重启nginx,浏览地址:
    浏览器截图
    4.测试alias:

    修改配置文件:

    location /root{
          alias  /usr/local/nginx/html/alias/;
          index index.html;
    }
    
    5.重启nginx,浏览地址:
    浏览器截图
    6.两个区别:

    1.root的访问目录是 root配置路径+location后面的访问路径;
    2.alias的访问目录是 alias配置路径;
    3.alias只能位于location块中。(root可以不放在location中);
    4.alias是一个目录别名的定义,root则是最上层目录的定义。

    相关文章

      网友评论

          本文标题:NGINX----应用----root和alias

          本文链接:https://www.haomeiwen.com/subject/tfgdahtx.html