美文网首页
nginx url 正则匹配v0.1

nginx url 正则匹配v0.1

作者: Go_python_Linux | 来源:发表于2021-05-19 16:43 被阅读0次

    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;
        }
    
      }
    
    

    相关文章

      网友评论

          本文标题:nginx url 正则匹配v0.1

          本文链接:https://www.haomeiwen.com/subject/fqwpjltx.html