美文网首页
2018-07-10-niginx-location-try_f

2018-07-10-niginx-location-try_f

作者: 迪奥炸 | 来源:发表于2018-07-10 16:25 被阅读0次

    http://blog.51cto.com/tongcheng/1427194

    http://www.nginx.cn/4658.html

    try_files指令是按顺序检测文件的存在性,并且返回第一个找到文件的内容,如果第一个找不到就会自动找第二个,依次查找.其实现的是内部跳转.以下举例说明:

    location /abc {

    try_files /4.html /5.html @qwe;      --检测文件4.html和5.html,如果存在正常显示,不存在就去查找@qwe值

    }

    nginx指定文件路径有两种方式root和alias,指令的使用方法和作用域:

    [root]

    语法:root path

    默认值:root html

    配置段:http、server、location、if

    [alias]

    语法:alias path

    配置段:location

    root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上

    root的处理结果是:root路径+location路径

    alias的处理结果是:使用alias路径替换location路径

    alias是一个目录别名的定义,root则是最上层目录的定义。

    还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可无~~

    反向代理proxy_pass

    proxy_pass配置说明

    不带/

    location /test/

    {

    proxy_pass http://t6:8300;

    }

     带/

    location /test/

    {

    proxy_pass http://t6:8300/;

    }

    上面两种配置,区别只在于proxy_pass转发的路径后是否带 “/”

    针对情况1,如果访问url = http://server/test/test.jsp,则被nginx代理后,请求路径会便问http://proxy_pass/test/test.jsp,将test/ 作为根路径,请求test/路径下的资源

    针对情况2,如果访问url = http://server/test/test.jsp,则被nginx代理后,请求路径会变为 http://proxy_pass/test.jsp,直接访问server的根资源

    相关文章

      网友评论

          本文标题:2018-07-10-niginx-location-try_f

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