zoukankan      html  css  js  c++  java
  • nginx*

    作用

      server name 为虚拟服务器的识别路径。因此不同的域名会通过请求头中的HOST字段,匹配到特定的server块,转发到对应的应用服务器中去。
     

    案例

    修改nginx.conf
    server {
     listen 80;
     server_name www;
     location / {
      default_type text/html;
      content_by_lua '
       ngx.say("<p>first</p>")
      ';
     }
    }
     
    server {
     listen  80;
     server_name www.zkh.com;
     location / {
      default_type text/html;
      content_by_lua '
       ngx.say("<p>second</p>")
      ';       
     }
    }
     
    server {
     listen 80;
     server_name www.zkh.*;
     location / {
      default_type text/html;
      content_by_lua '
       ngx.say("<p>third</p>")
      ';
     
     }
    }
     
    server {
     listen 80;
     server_name ~w+.com;
     location / {
      default_type text/html;
      content_by_lua '
       ngx.say("<p>forth</p>")
      ';       
     }
    }
     
    server {
     listen 80;
     server_name ~.*zkh.com;
     location / {
      default_type text/html;
      content_by_lua '
       ngx.say("<p>fifth</p>")
      ';
     }
    }
      修改hosts文件
      118.126.100.138 www.zkh.com
      118.126.100.138 www.zkh.org
      118.126.100.138 zkh.com
      118.126.100.138 zkh.org

     
     
    通过jmeter查看请求头,发现请求头携带了Host,由此可知nginx必定会拿它做uri匹配工作
     
    匹配顺序
      server_name与host匹配优先级如下:
      1、完全匹配
      2、通配符在前的,如*.test.com
      3、在后的,如www.test.*
      4、正则匹配,如~^.www.test.com$
      如果都不匹配
      1、优先选择listen配置项后有default或default_server的
      2、找到匹配listen端口的第一个server块
    ————————————————
    版权声明:本文为CSDN博主「Kevin_K_H_ZHENG」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/cheng_kohui/article/details/82930464
  • 相关阅读:
    Lua 有关字符串的剪切 以及匹配
    [Decode error
    mac 终端 常用命令
    mac apache 相关终端命令
    spring boot架构设计——权限验证及API接口统一返回格式
    ios 官网文档翻译—Create a Table View(swift)
    quicksqlite简介
    android ndk 环境搭建和简单实例
    android 关闭软键盘
    android 弹出全局加载等待动画
  • 原文地址:https://www.cnblogs.com/helloworldmybokeyuan/p/11597733.html
Copyright © 2011-2022 走看看