简体   繁体   中英

Nginx rewrite and proxy_pass explanation

I can see a following locations in nginx/okd configuration:

    location /STFlow/ {
        rewrite ^/STFlow(.*)$ $1 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 $1;
        }
        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;
    }

In location /STFlow/ are four lines below rewrite ^/STFlow(.*)$ $1 last; ever executed?

If so when?

What's the point of them?

If that rewrite rule had a break flag instead of last , it would remove the /STFlow prefix from /STFlow/some/path URI before passing it to the upstream, ie do the same as the second location block except of setting debug-header and $realip variable. But as far as I understand using the last flag makes that four lines never executed, further URI processing would be done inside the second location block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM