zoukankan      html  css  js  c++  java
  • 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
    ';
            }

    访问 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;

  • 相关阅读:
    POI Excel解析
    mysql忘记root密码的解决方法
    注解实现AOP
    Java 集合类
    easyui-textbox 绑定事件
    MarqueeLabel 跑马灯
    Swift-2.14构造过程
    Swift-2.13继承
    Swift- 2.12下标脚本
    Swift-2.11方法
  • 原文地址:https://www.cnblogs.com/jackey2015/p/10375549.html
Copyright © 2011-2022 走看看