Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if condition concatenation in nginx conf file

Tags:

nginx

I'm trying to do this in a nginx conf file but it doesn't work :

if ($scheme://$host = 'http://example.com') {
  return 301 https://example.com$request_uri;
}

So how can I concatenate $scheme and $host in the if condition ?

like image 302
Kevin Vincent Avatar asked Oct 19 '25 21:10

Kevin Vincent


1 Answers

It's easy with a temp variable

set $tmp $scheme://$host;
if ($tmp = 'http://example.com') {
    return 301 https://example.com$request_uri;
}
like image 141
Larry.He Avatar answered Oct 23 '25 03:10

Larry.He