如何精确匹配nginx位置?

时间:2017-03-20 20:07:19

标签: nginx nginx-location

我正在配置nginx revser代理。结果应该是当用户键入http://10.21.169.13/mini时,请求应为proxy_pass to 192.168.1.56:5000。这是nginx配置:

server {
        listen 80;
        server_name 10.21.169.13;

        location = /mini {
                proxy_pass http://192.168.1.65:5000;
                include /etc/nginx/proxy_params;
        }
}

以上location块从未与http://10.21.169.13/mini一起使用。唯一有效的location块是:

server {
        listen 80;
        server_name 10.21.169.13;

        location  / {
                proxy_pass http://192.168.1.65:5000;
                include /etc/nginx/proxy_params;
        }
}

但是上面的配置也匹配http://10.21.169.13请求太多了。

哪个location块只匹配'http://10.21.169.13/mini`而不再匹配?

更新:尝试了以下内容并失败:

 location  /mini {
                    proxy_pass http://192.168.1.65:5000;
                    include /etc/nginx/proxy_params;
            }

location  /mini/ {
                    proxy_pass http://192.168.1.65:5000;
                    include /etc/nginx/proxy_params;
            }

错误为request not found

1 个答案:

答案 0 :(得分:1)

试试这个:

server {
    listen 80;
  server_name 10.21.169.13;

  # root /usr/share/nginx/html;
    # index index.html index.htm;

  location  / {
        # add something here to handle the root
        # try_files $uri $uri/ /index.html;
    }

  location  /mini {
    proxy_pass http://192.168.1.65:5000;
    include /etc/nginx/proxy_params;
    }

}

请告诉我这是否适合您。