nginx location正则匹配

location正则匹配需要以~开头:

server {
    listen       443 ssl;
    server_name  qingbao.hnzycfc.com;

    ssl_certificate      /home/centos/nginx/ca/your.pem;
    ssl_certificate_key  /home/centos/nginx/ca/your.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location ~ ^/(fcd|wci)/ {
        proxy_pass http://tomcats;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        proxy_buffer_size 4k;
        
        # websocket support websocket支持
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location ~ / {
        root   /home/centos/www;
        index  index.html index.htm;

        rewrite ^/(.*)/(.*\.js$) /$1/$2 break;
        rewrite ^/(.*)/(.*\.map$) /$1/$2 break;
        rewrite ^/(.*)/(.*\.css$) /$1/$2 break;
        rewrite ^/(.*)/(.*\.(png|jpg|gif|ico)$) /$1/$2 break;
        rewrite ^/(.*)/(.*\.(ttf|woff|woff2|svg|otf|eot)$) /$1/$2 break;
        rewrite ^/(.*)/ /$1/index.html break;
        
        # websocket support websocket支持
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location / {
        rewrite ^(.*) https://$host/xxx permanent;
    }
}

1.如果最前面的location正则匹配到了,后面的location就不会执行;
2.越详细的匹配放在最前面,如对接口的location正则配置放在最前,其次是网址正则配置,最后是根路径的重写;

你可能感兴趣的:(服务器)