【Nginx】Nginx location 中root alias error_page 404 路径部分是否/开头的理解

注意:路径中 所有// nginx已/处理 , root和alias的区别请另百度一下

第一种 error_page 404 /开头,正常访问localhost:8080:work-order ,404访问localhost:8080:work-order/home

root

location ^~ /work-order/ {
   
        root   basePath/test/;
        index  index.html index.htm;
        error_page  404           /work-order/index.html;
      }
status 200: basePath/test//work-order//index.html 
status 404: basePath/test//work-order/index.html  /开头代表从basePath后开始替换

location ^~ /work-order/ {
        root   basePath/test/;
        index  index.html index.htm;
        error_page  404           /wen/index.html;
      }
status 200: basePath/test//work-order//index.html
status 404: basePath//wen/index.html  /开头代表从basePath后开始替换 注:此时访问的是localhost:8080:wen 匹配不到/work-order了

alias

location ^~ /work-order {
       alias   basePath/test/work/;
       index  index.html index.htm;
       error_page  404         /work-order/index.html;
     }
 
status 200: basePath/test//work//index.html
status 404: basePath/test//work/index.html  /work-order/index.html;  /开头代表从basePath后开始替换

location ^~ /work-order {
       alias   basePath/test/work/;
       index  index.html index.htm;
       error_page  404           /wen/index.html;
     }
 
status 200: basePath/test//work//index.html
status 404: basePath//wen/index.html   /开头代表从basePath后开始替换 注:此时访问的是localhost:8080:wen 匹配不到/work-order了

第二error_page 404 没有 /开头,访问localhost:8080:work-order,404访问localhost:8080:work-order/home

root

location ^~ /work-order/ {
   
        root   basePath/test/;
        index  index.html index.htm;
        error_page  404           work-order/index.html;
      }
status 200: basePath/test//work-order//index.html 
status 404: basePath/test//work-order/work-order/work-order/work-order/index.html   没有/开头表示相对路径  因为一直404所以/work-order/work-work-order/wen

location ^~ /work-order/ {
        root   basePath/test/;
        index  index.html index.htm;
        error_page  404           wen/index.html;
      }
status 200: basePath/test//work-order//index.html
status 404: basePath/test///work-order/wen/wen/wen/index.html 没有/开头表示相对路径  ,因为一直404所以/wen/wen/wen

alias

location ^~ /work-order {
       alias   basePath/test/work/;
       index  index.html index.htm;
       error_page  404     work-order/index.html
     }
 
status 200: basePath/test//work//index.html
status 404: basePath/test//work/work-order/work-order/work-order/index.html; 没有/开头表示相对路径,因为一直404所以/work-order/work-work-order/wen

location ^~ /work-order {
       alias   basePath/test/work/;
       index  index.html index.htm;
       error_page  404           wen/index.html;
     }
 
status 200: basePath/test//work//index.html
status 404: basePath/test//work//wen/wen/wen/wen/index.html   /开头代表从basePath后开始替换 因为一直404所以/wen/wen/wen
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值