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

Thursday, September 1, 2022

[FIXED] How does Nginx proxy_pass pass a route parameter

 September 01, 2022     docker, endpoint, nginx, nginx-config, nginx-reverse-proxy     No comments   

Issue

I'm trying to make an api call to an internal docker container, but for every request url I have to make a proxy_pass in the Nginx config. I've read articles that the slashes at the end should work to pass all after de certain url to the proxy_pass.

Read here (redirect table)


Example

www.example.com/api -> redirects to correct endpoint

www.example.com/api/2020 -> this doesn't redirect to http://api/2020

Configuration

location = /api/ {
   proxy_pass http://api/;
}

So why doesn't this configuration pass the 2020 'parameter' to the api endpoint? It works when I make a configuration like this:

location = /api/2020 {
   proxy_pass http://api/2020;
}

But the problem is that it's a parameter so it can possibly be any number, how to solve this?

I've read other posts, but I ask this question again to get a broader understanding of the passing possibilities for parameters. Is it really necessary to use Regex for this?


Solution

Remove exact matching, just use

location /api/ {
   proxy_pass http://api/;
}

without any regexes.



Answered By - Ivan Shatsky
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