Nginx CONTENT阶段 static模块

L63-65

 

 

alias指令 

syntax: alias path;# 静态文件路径  alias不会将请求路径后的路径添加到 path中

context : location;

root指令

syntax : root path; #静态文件路径 root会将请求路径后添加的 path中

context : http,server,location,if in location

      location /root {
                root html;
        }
        location /alias{
                alias html;
        }

        location ~/root/(\w+\.txt){
                root html/first/$1;
        }
        location ~/alias/(\w+\.txt){
                alias html/first/$1;
        }    

访问 http://xxxx/root 返回404 通过error日志 可以看到 会在html后加上root目录 

访问 http://xxxx/alias 返回nginx主页面 返回正确 

访问 http://xxxx/root/1.txt 返回404

访问 http://xxxx/alias/1.txt 则返回1.txt内容 

 

 static模块三个变量

request_filename : 访问文件的完整路径包括扩展名

document_root : 由URI和root/alias规则生成的文件夹路径 

realpath_root : 将document_root软连接替换成真实路径

location /realpath{
                alias html/realpath;
                return 200 '$request_filename:$document_root:$realpath_root\n';
        }

访问 http://xxxx/realpath/1.txt 则返回 /usr/local/nginx/html/realpath/1.txt:/usr/local/nginx/html/realpath:/usr/local/nginx/html/realpath 输出的路径

当用户访问资源时没有在末尾加反斜杠的时候 NGINX会返回一个301的重定向

 指令 absolute_redirect  

syntax: on | off;

default : on;

context : http,server,location 

 server {
        listen       80;
        server_name  localhost;


        absolute_redirect  off; #关闭的时候 
        port_in_redirect on;
}

演示:当关闭absolute_redirect的时候 curl http://116.196.123.9/alias -i

当访问后  看到头部是不带域名的

Server: nginx/1.14.2
Date: Fri, 15 Feb 2019 08:26:21 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: /alias/  #我们看到没有完整域名

当打开的时候 就有 Location: http://192.xxx.xxx.1/alias/

指令 port_in_redirect 

syntax : on | off;

defaut : on;

context : http,server,location;

指令 server_name_in_redirect 主要控制 是否返回的 host域名 还是server_name主域名

syntax : on | off;

default : off;

context : http,server,location;

 

转载于:https://www.cnblogs.com/jackey2015/p/10375549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值