同理,訪問(wèn)http://192.168.1.23/proxy/test.html就會(huì)被代理到http://192.168.1.5:8090/hahatest.html
[root@localhost conf.d]# curl http://192.168.1.23/proxy/index.html 192.168.1.5 hahaindex.html
注意,這種情況下,不能直接訪問(wèn)http://192.168.1.23/proxy/,后面就算是默認(rèn)的index.html文件也要跟上,否則訪問(wèn)失??!
————————————————————————————-
上面四種方式都是匹配的path路徑后面加/,下面說(shuō)下path路徑后面不帶/的情況:
1)第一種情況,proxy_pass后面url帶/:
[root@localhost conf.d]# cat test.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
location /proxy {
proxy_pass http://192.168.1.5:8090/;
}
}
[root@localhost conf.d]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
2)第二種情況,proxy_pass后面url不帶/
[root@localhost conf.d]# cat test.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
location /proxy {
proxy_pass http://192.168.1.5:8090;
}
}
[root@localhost conf.d]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
[root@localhost conf.d]#
這樣配置的話,訪問(wèn)http://103.110.186.23/proxy會(huì)自動(dòng)加上/”(即變成http://103.110.186.23/proxy/),代理到192.168.1.5:8090/proxy/
3)第三種情況
[root@localhost conf.d]# cat test.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
location /proxy {
proxy_pass http://192.168.1.5:8090/haha/;
}
}
[root@localhost conf.d]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
這樣配置的話,訪問(wèn)http://103.110.186.23/proxy會(huì)自動(dòng)加上/”(即變成http://103.110.186.23/proxy/),代理到http://192.168.1.5:8090/haha/
4)第四種情況:相對(duì)于第三種配置的url不加/
[root@localhost conf.d]# cat test.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
location /proxy {
proxy_pass http://192.168.1.5:8090/haha;
}
}
[root@localhost conf.d]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
這樣配置的話,訪問(wèn)http://103.110.186.23/proxy,和第三種結(jié)果一樣,同樣被代理到http://192.168.1.5:8090/haha/
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)西部數(shù)碼的支持。
更多關(guān)于云服務(wù)器,域名注冊(cè),虛擬主機(jī)的問(wèn)題,請(qǐng)?jiān)L問(wèn)西部數(shù)碼官網(wǎng):www.ps-sw.cn