NGINX proxy_pass URL with parameters to another path - nginx

I tried the following config in my nginx proxy:
location /new/path {
proxy_pass http://IP_Address:PORT/old/path.html?jh=twrtax2jlqs5t07d556lfhpfn3he0og;
}
After that, I tested it with the following URL: domain.com/new/path
My Browser shows the new path URL but in the background it opens /old/path.html without the rest after the question mark....
Any ideas? Whats wrong?

Related

location prefix matching nginx doesn't work with variables

Hi Earlier I was matching location prefix uri matching to get the redirection to website www.example.com/abc/ from www.example.com/bbb/abc(requested uri).
server {
location /bbb/ {
proxy_pass http://www.example.com/;
}
}
Earlier I was requesting on www.example.com/bbb/abc and getting redirected to www.example.com/abc
as I required
However now the problem is I've resolver and I'm also using variable. This is done to ensure that nginx starts even if one of the upstream services are down and it won't show the error of
[nginx] host upstream not found
server {
location /bbb/ {
resolver 127.0.0.11 valid=some secs;
set $example www.example.com
proxy_pass http://$example/;
}
}
Now that I'm using variable, I think url location prefix match is not working as I am sending request on www.example.com/bbb/abc , and it shows the nginx 404 not found.
Can anyone guide me how redirect properly with variable and resolver included.

Nginx - Passing parameters through to proxy_pass

I'm new to nginx - am using Vouch proxy and trying to utilise its logout redirect: https://github.com/vouch/vouch-proxy#logout-endpoint-redirection
In my app I'm hitting a URL like: mydomain.com/tools/app/logout?url={somevalue}
Then in nginx I'm passing this onto vouch proxy with
location /tools/app/logout {
proxy_pass http://vouch/logout;
}
However is it possible to pass that ?url={somevalue} parameter too? Basically append to proxy_pass http://vouch/logout?
Any help appreciated.
Thanks.

NGINX rewrite location without changing url

When visiting /abc/sitemap.xml I'd like to display the content of /abc/sitemap?output=xml without changing the url.
Currently, it shows the right content, but changes the url to /abc/sitemap?output=xml instead of keeping /abc/sitemap.xml, and here is my config.
location /abc/sitemap.xml {
rewrite ^ /abc/sitemap?output=xml;
}
Thanks
How about a proxy_pass:
location /abc/sitemap.xml {
proxy_pass http://$host/abc/sitemap?output=xml;
}
Note: use HTTP or HTTPS depending on your SSL configurations.

NGINX: proxy_pass for a dynamic url

I have a docker container which serves a web application on:
my.server.domain:8080
When I request that URL with a browser, it is automatically redirected to the login page:
http://my.server.domain:8080/login
I'm trying to proxy the app so that I can avoid to use the port number.
Two possible ways to achieve that are:
1) http://my.server.domain/appname
2) http://appname.my.server.domain
Either way, will work for me.
But I'm struggling with making the right NGINX configuration.
I tried with:
location /appname {
proxy_pass http://my.server.domain:8080/;
}
But when I load http://my.server.domain/appname it gets redirected to http://my.server.domain/login which doesn't exist.
If I use / it works as expected:
location / {
proxy_pass http://my.server.domain:8080/;
}
But that's not what I need.
I can add more directives like:
location /login {
proxy_pass http://my.server.domain:8080/login;
}
But then it will fail on the next redirect and so on ..

Routing in nginx URI with same prefix as another URI

Currently trying to use Nginx as a proxy and finding some difficulties with routes having another URI as a prefix. Example :
location /api/route/to/specific/application {
proxy_pass http://proxying.to/site/A;
}
location /api {
proxy_pass http://proxying.to/another/site/B;
}
When visiting http://mysite.io/api/route/to/specific/application, I get a 404 from Nginx while when I visit http://proxying.to/site/A directly I get the expected page.
Any idea how I can make it work ?
Thanks

Resources