Welcome! Log In Create A New Profile

Advanced

variable for domain name in redirect

June 30, 2018 02:57PM
Hello,

I have something in one of my server bloc:


```
# switch to TLS for page.php, contact.php, faq.php, known https sources and /
if ($scheme = http) {
set $rule_9 1$rule_9;
}
if ($outdated = 0){
set $rule_9 2$rule_9;
}
if ($request_uri ~ "^/(auction|biglemon|carview(-bike)?|carsensor(-c)?|daihatsu|gazoo|goo(bike(-catalog)?|net)|honda|koubai|kuriyama-truck|kurumaerabi(-search)?|truck-reparts(-b)?|truskey|list1|pdns|rakuten|page|faq|contact(_japan)?|jpa(-b|L1)?|_jpa[23])\.php|^/(\?.*)?$") {
set $rule_9 3$rule_9;
}
if ($rule_9 = "3210"){
return 301 https://www.server.com$request_uri;
}
```

Then something similar in another

```
# switch to TLS for page.php, contact.php, faq.php, known https sources and /
if ($scheme = http) {
set $rule_9 1$rule_9;
}
if ($outdated = 0){
set $rule_9 2$rule_9;
}
if ($request_uri ~ "^/(auction|biglemon|carview(-bike)?|carsensor(-c)?|daihatsu|gazoo|goo(bike(-catalog)?|net)|honda|koubai|kuriyama-truck|kurumaerabi(-search)?|truck-reparts(-b)?|truskey|list1|pdns|rakuten|page|faq|contact(_japan)?|jpa(-b|L1)?|_jpa[23])\.php|^/(\?.*)?$") {
set $rule_9 3$rule_9;
}
if ($rule_9 = "3210"){
return 301 https://dev.server.com$request_uri;
}
```

The problem is that have several servers.

1 - Is there a way to use variable for the some server names in the 'return 301' line so I could use shared code and not have to edit this snippet everywhere another site turns https?

2 - I have a lot of those return 301 where code could be shared if something like this were available e.g. $scheme://$actual_real_server_name$request_uri

Difficulty, the server_name can and often contains multiple entries.

I have found nothing useful about this on serverfault nor anywhere else. Dealing with this for several years.

Thanks!
Subject Author Posted

variable for domain name in redirect

shiz June 30, 2018 02:57PM

Re: variable for domain name in redirect

Maxim Dounin July 01, 2018 11:20AM

Re: variable for domain name in redirect

shiz July 01, 2018 03:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready