Nginx 重写和 proxy_pass 解释
Nginx rewrite and proxy_pass explanation
我可以在 nginx/okd 配置中看到以下位置:
location /STFlow/ {
rewrite ^/STFlow(.*)$ last;
#
# Are four lines below executed if rewrite has last option ???
# What's the point of them?
#
proxy_pass http://zuul-proxy:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
}
location / {
add_header debug-header dbg5;
set $realip $remote_addr;
if ($http_x_forwarded_for ~ "^(\d+\.\d+\.\d+\.\d+)") {
set $realip ;
}
proxy_pass http://zuul-proxy:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
client_max_body_size 50M;
}
在 location /STFlow/
下面四行 rewrite ^/STFlow(.*)$ last;
曾经执行过吗?
如果是什么时候?
它们有什么意义?
如果该重写规则有一个 break
标志而不是 last
,它会在将 /STFlow/some/path
URI 传递给上游之前从 /STFlow
前缀中删除它,我. e.除了设置 debug-header
和 $realip
变量外,与第二个 location
块执行相同的操作。但据我所知,使用 last
标志会使四行代码永远不会执行,进一步的 URI 处理将在第二个 location
块内完成。
我可以在 nginx/okd 配置中看到以下位置:
location /STFlow/ {
rewrite ^/STFlow(.*)$ last;
#
# Are four lines below executed if rewrite has last option ???
# What's the point of them?
#
proxy_pass http://zuul-proxy:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
}
location / {
add_header debug-header dbg5;
set $realip $remote_addr;
if ($http_x_forwarded_for ~ "^(\d+\.\d+\.\d+\.\d+)") {
set $realip ;
}
proxy_pass http://zuul-proxy:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
client_max_body_size 50M;
}
在 location /STFlow/
下面四行 rewrite ^/STFlow(.*)$ last;
曾经执行过吗?
如果是什么时候?
它们有什么意义?
如果该重写规则有一个 break
标志而不是 last
,它会在将 /STFlow/some/path
URI 传递给上游之前从 /STFlow
前缀中删除它,我. e.除了设置 debug-header
和 $realip
变量外,与第二个 location
块执行相同的操作。但据我所知,使用 last
标志会使四行代码永远不会执行,进一步的 URI 处理将在第二个 location
块内完成。