Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Can I use variable in regular expression?

$
0
0
(Please excuse my English)

I'm writing a Nginx configuration file using 'if' statement.
Below is a part of the configuration file and it works well.

---
set $destination $http_destination;
set $scheme_host "$scheme://$host"; # $scheme_host = "https://your.host.com"
.......
.......
if ($destination ~ ^https://your.host.com/(.*)$) {
set $temp $1;
}
---

However, when I changed the above 'if' clause like below, but it did not work.
It seems that variables cannot be used in the regular expression.

---
if ($destination ~ ^\$scheme_host/(.*)$) {
set $temp $1;
}
---

How can I use variables in the regular expression?
Or write configuration works the same way?

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>