PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

[FIXED] how to get url parameter and pass to proxy_pass using nginx

 September 02, 2022     nginx, nginx-config, nginx-reverse-proxy     No comments   

Issue

I need to get the parameter from an URL, for example, abc=MY_STRING:

https://my-address/test?abc=MY_STRING

And at the reverse proxy (my-address), is configured like this:

location /test?(.*) {
  proxy_pass http://local-server:1234/test?$args
}

but it is not working.

I tried another configuration:

location /test?(.*) {
  proxy_pass http://local-server:1234/test?$1
}

but not worked too.


Solution

You cannot match the query string part of the URI with a location or rewrite statement, as it is not part of the normalized URI.

But you don't need to. The URI (complete with query string) will be passed upstream unless you redirect it using a rewrite or try_files statement.

For example:

location /test {
    proxy_pass http://localhost:1234;
}

The URI /test?abc=MY_STRING will match the location and be passed to localhost:1234 exactly the same. See this document for more.



Answered By - Richard Smith
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing