前言
主要是记录proxy_pass在做转发时,转发的url生成规则,本文以通用字符串匹配为例,就是类似如下
location /aaa {
proxy_pass ...
}
正则及精准匹配放到下篇说
正文
对于访问后端路径的拼接,proxy_pass可以分为两种,一种是携带URI(或者说是某个uri的一部分),一种是不带uri(或者说仅有协议 + host)
例如 http://localhost:80 就是不带uri的地址
例如 http://localhost:80/ 和 http://localhost:80/aaa 就是携带URI的地址
以下案例全部是假设 nginx设置server 为example.com,即
http {
server {
listen 8080;
server_name example.com;
}
}
不带uri
这种比较好说,访问nginx的URI直接拼接到proxy_pass的后面就可以了,举例如下
location /aaa {
proxy_pass http://localhost
}
location /aaa/ {
proxy_pass http://localhost
}
1、对于上面两种写法,访问nginx的URL为 http://example.com:8080/aaa/xxx,nginx转发的地址将是 http://localhost/aaa/xxx
2、但是对于http://exam