nginx url 正则匹配v0.1

nginx 正则备忘记录

 server {
    listen 80;
    listen [::]:80;
    server_name test.name;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # 精确匹配
    location = /google   {
      rewrite ^ http://google.com;
    }
    # 前缀匹配
    location ^~ /baidu  {
      rewrite ^ http://baidu.com;
    }
    # 正则匹配 区分大小写
    location ~ /sogou  {
      rewrite ^ http://sogou.com/;
    }
    # 正则匹配 不 区分大小写
    location ~* /SoGou  {
      rewrite ^ http://sogou.com/;
    }
    # 正常匹配 优先级低于前缀匹配 (可使用正则,不区分大小写)
    location /biying  {
       rewrite ^ http://biying.com/;
    }
    # 全匹配
    location / {
      root   /usr/share/nginx/html;
    }
    # 别名匹配
    error_page 404 = @notfound;

    location @notfound {
     rewrite ^ http://taobao.com/;
    }
    
    location = /50x.html {
      root   /usr/share/nginx/html;
    }

  }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。