同理,訪問http://192.168.1.23/proxy/test.html就會被代理到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
注意,這種情況下,不能直接訪問http://192.168.1.23/proxy/,后面就算是默認(rèn)的index.html文件也要跟上,否則訪問失敗!
————————————————————————————-
上面四種方式都是匹配的path路徑后面加/,下面說下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]#
這樣配置的話,訪問http://103.110.186.23/proxy會自動加上/”(即變成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
這樣配置的話,訪問http://103.110.186.23/proxy會自動加上/”(即變成http://103.110.186.23/proxy/),代理到http://192.168.1.5:8090/haha/
4)第四種情況:相對于第三種配置的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
這樣配置的話,訪問http://103.110.186.23/proxy,和第三種結(jié)果一樣,同樣被代理到http://192.168.1.5:8090/haha/
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對三五互聯(lián)的支持。
更多關(guān)于云服務(wù)器,域名注冊,虛擬主機(jī)的問題,請訪問三五互聯(lián)官網(wǎng):m.shinetop.cn