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

Friday, June 24, 2022

[FIXED] How to use nginx proxy with access token in url?

 June 24, 2022     nginx, reverse-proxy     No comments   

Issue

I'm running nginx as a proxy for my backend services. I want to use url as http://IP:PORT/<token>/endpoint and which should be proxied to url as http://backend/endpoint

nginx.conf file:-

server {
    listen 80;
    location / {
        proxy_pass         http://backend;
        proxy_set_header Authorization "Basic safdadfWU6cdfdvcmQ=";
    }
}

Here I want to take <token> out of the url and pass remaining endpoint to my proxy_pass server. Kindly help me.


Solution

Thank you @Richard, Your suggestions helped in solving my Question. For other people's reference, the update nginx.conf file:-

server {
    listen 80;
    location / {
        rewrite ^/[^/]+(/.*)$ $1 break;
        proxy_pass         http://backend;
        proxy_set_header Authorization "Basic safdadfWU6cdfdvcmQ=";
    }
}

Now I'm able to use url as http://IP:PORT/<token>/endpoint and which should be proxied to url as http://backend/endpoint



Answered By - nandal
Answer Checked By - Marilyn (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