如何精确匹配 nginx 位置?
How to exact match a 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
。
试试这个:
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;
}
}
让我知道这是否适合你。
我正在配置 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
。
试试这个:
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;
}
}
让我知道这是否适合你。