proxy_pass
proxy_pass url 后的 / 问题
下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。
location /proxy/ {
proxy_pass http://127.0.0.1/;
}
http://127.0.0.1/test.html
location /proxy/ {
proxy_pass http://127.0.0.1;
}
http://127.0.0.1/proxy/test.html
location /proxy/ {
proxy_pass http://127.0.0.1/aaa/;
}
http://127.0.0.1/aaa/test.html
location /proxy {
proxy_pass http://127.0.0.1/aaa/;
}
http://127.0.0.1/aaa/test.html
location /proxy/ {
proxy_pass http://127.0.0.1/aaa;
}
http://127.0.0.1/aaatest.html
-------------------------------------------------------------------------------------
location /proxy {
proxy_pass http://127.0.0.1/aaa;
}
http://127.0.0.1/aaa/test.html
upstream
定义一组服务器。 这些服务器可以监听不同的端口。 而且,监听在TCP和UNIX域套接字的服务器可以混用。
http{
upstream user{
server 192.168.1.2:8081 weight=5;
server 192.168.1.3:8081 weight=2;
server 192.168.1.4:8081 max_fails=3 fail_timeout=30s;
#server unix:/tmp/backend;
}
...
server{
listen 80;
....
location /user/ {
proxy_pass http://user;
}
}
}
访问localhost/user/aaa/bbb 就会被代理到 192.168.1.2:8081/user/aaa/bbb 192.168.1.3:8081/user/aaa/bbb 192.168.1.4:8081/user/aaa/bbb
|