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

Thursday, September 1, 2022

[FIXED] How to remove some part of path in nginx reverse proxy

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

Issue

I've set frontend api url endpoint to something like this https://host/api/login which is host means nginx reverse proxy

Inside nginx config I've done something like this

location ~* ^/api/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://somehost/$1$is_args$args;
}

I don't sure if it's correct but above code I want it to catch request that has /api at the first path and send request to proxy_pass's url along with the same path. But I don't want to use /api for this.

For example if frontend has request to /api/login path. I want to send request to http://somehost/login. So how can I remove /api inside nginx.conf file ?


Solution

I'd do

location /api/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://somehost/;
}


Answered By - Hans Kilian
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