1

Suppose there's a nginx configuration:

server {
    ...
    location /nakayoshi {
        if ($georedirect) {
            proxy_pass http://foo.bar/fa/fb/fc;
        }
        proxy_pass http://foo.bar/fa/fb/fd;
    }
}

When I sudo nginx -t, it prints out:

nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular express, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/nakayoshi.conf

Also I've found rewrite help me here, but the redirected uri will change to urls like "http://foo.bar/fa/fb/fc".

Can I keep the redirected uris unchanged with proxy_pass?

1 Answer 1

2

Try something like this

http {
    ...
    map $georedirect $proxyuri {
        "" fa/fb/fd;
        default fa/fb/fc;
    }
    server {
        ...
        location /nakayoshi {
            proxy_pass http://foo.bar/$proxyuri;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.