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

Friday, June 24, 2022

[FIXED] How to remove slash from $http_referer variable

 June 24, 2022     nginx, nginx-config, nginx-reverse-proxy, reverse-proxy, web     No comments   

Issue

I want to use NGINX as dynamic local CDN with proxy_pass based on Referer header and $http_refere variable. The problem is that the Referer (variable too) header contains a "/" at the end of the URL. I want to delete trailing slash in $http_referer. How can I do it?

My NGINX location:

location / {
  add_header 'Access-Control-Allow-Origin' '*';
  add_header Referrer-Policy 'strict-origin';
  proxy_pass $http_referer;
}

Solution

You can do it either via if block:

set $proxy $http_referer;
if ($http_referer ~ ^(.*)/$) { set $proxy $1; }

or via map directive:

map $http_referer $proxy {
    ~^(.*)/$  $1;
    default   $http_referer;
}

Then use the $proxy variable with the proxy_pass directive:

proxy_pass $proxy;


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