nginx配置location得/
location目录后加"/",只能匹配目录,不加“/”不仅可以匹配目录还对目录进行模糊匹配。而proxy_pass无论加不加“/”,代理跳转地址都直接拼接。
server {
listen 80;
server_name localhost;
location /chendada01/ {
proxy_pass http://localhost:8080;
}
http://localhost/chendada02/xxx -> http://localhost:8080/xxx
location /chendada02/ {
proxy_pass http://localhost:8080/;
}
http://localhost/chendada03/xxx -> http://localhost:8080/chendada03*/xxx
location /chendada03 {
proxy_pass http://localhost:8080;
}
http://localhost/chendada04/xxx -> http://localhost:8080//xxx,请注意这里的双斜线,好好分析一下。
location /chendada04 {
proxy_pass http://localhost:8080/;
}
http://localhost/chendada05/xxx -> http://localhost:8080/hahaxxx,请注意这里的haha和xxx之间没有斜杠,分析一下原因。
location /chendada05/ {
proxy_pass http://localhost:8080/haha;
}
http://localhost/api6/xxx -> http://localhost:8080/haha/xxx
location /chendada06/ {
proxy_pass http://localhost:8080/haha/;
}
http://localhost/chendada07/xxx -> http://localhost:8080/haha/xxx
location /chendada07 {
proxy_pass http://localhost:8080/haha;
}
http://localhost/chendada08/xxx -> http://localhost:8080/haha//xxx,请注意这里的双斜杠。
location /chendada08 {
proxy_pass http://localhost:8080/haha/;
}
}
现在学习还不晚;