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

Saturday, June 25, 2022

[FIXED] How to set the proxy_pass to get the desired address?

 June 25, 2022     nginx, nginx-location, nginx-reverse-proxy, reverse-proxy, url-redirection     No comments   

Issue

I have been struggling with setting up Nginx for our use case.

When I set up Nginx with the following config:

location /dep-core {
    proxy_pass http://node-server:7070/;
}

and call the server with following endpoint: <END-POINT>/dep-core/api/login

the call is redirected to <ADDRESS-AFTER-RESOLUTION>//api/login with two leading //s.

and when I remove the trailing / in proxy_pass after 7070:

location /dep-core {
    proxy_pass http://node-server:7070;
}

the call is redirected to <ADDRESS-AFTER-RESOLUTION>/dep-core/api/login with leading /dep-core appended.

I want my call to redirect my call to: <ADDRESS-AFTER-RESOLUTION>/api/login What would be the standard way to achieve this??


Solution

For correct translation from /dep-core/foo to /foo, the location directive requires a trailing /.

For example:

location /dep-core/ { 
    proxy_pass http://node-server:7070/; 
}

See this document for details.


To translate /dep-core to /, you can use a rewrite...break with a clever regular expression in the second block of your question. But a simple solution is to add an exact match location for that single edge case.

For example:

location = /dep-core {
    rewrite ^ $uri/ last;
}
location /dep-core/ { 
    proxy_pass http://node-server:7070/; 
}


Answered By - Richard Smith
Answer Checked By - Mary Flores (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