nginx proxy_pass使用 详细
前端发起这样的请求:
http://192.168.0.2/test/aaa.txt
proxy_pass可以分为以下12
种情况
Scenario 1
...
location ^~ /test {
...
proxy_pass http://127.0.0.1;
}
代理后的实际URL为:
http://127.0.0.1/test/aaa.txt
Scenario 2
...
location ^~ /test {
...
proxy_pass http://127.0.0.1/;
}
代理后的实际URL为:
http://127.0.0.1/aaa.txt
Scenario 3
...
location ^~ /test {
...
proxy_pass http://127.0.0.1/joy;
}
代理后的实际URL为:
http://127.0.0.1/joyaaa.txt
Scenario 4
...
location ^~ /test {
...
proxy_pass http://127.0.0.1/joy/;
}
代理后的实际URL为:
http://127.0.0.1/joy/aaa.txt
Scenario 5
upstream test01 {
server 127.0.0.1;
}
server {
...
location ^~ /test {
...
proxy_pass http://test01/;
}
}
代理后的实际URL为:
http://127.0.0.1//aaa.txt
Scenario 6
upstream test01 {
server 127.0.0.1;
}
server {
...
location ^~ /test {
...
proxy_pass http://test01;
}
}
代理后的实际URL为:
http://127.0.0.1/test/aaa.txt
Scenario 7
upstream test01 {
server 127.0.0.1;
}
server {
...
location ^~ /test {
...
proxy_pass http://test01/joy;
}
}
代理后的实际URL为:
http://127.0.0.1/joy/aaa.txt
Scenario 8
upstream test01 {
server 127.0.0.1;
}
server {
...
location ^~ /test {
...
proxy_pass http://test01/joy/;
}
}
代理后的实际URL为:
http://127.0.0.1/joy//aaa.txt
Scenario 9
server {
...
set $test_url "a.b.c";
location ^~ /test {
...
proxy_pass http://$test_url/joy/;
}
}
代理后的实际URL为:
http://127.0.0.1/joy/
Scenario 10
server {
...
set $test_url "a.b.c";
location ^~ /test {
...
proxy_pass http://$test_url/joy;
}
}
代理后的实际URL为:
http://127.0.0.1/joyaaa.txt
Scenario 11
server {
...
location ^~ /test {
...
proxy_pass http://a.a.a/joy;
}
}
代理后的实际URL为:
http://127.0.0.1/joyaaa.txt
Scenario 12
server {
...
location ^~ /test {
...
proxy_pass http://a.a.a/joy/;
}
}
代理后的实际URL为:
http://127.0.0.1/joy/aaa.txt