P
P
Pavel Bezrukov2013-12-12 00:08:22
Nginx
Pavel Bezrukov, 2013-12-12 00:08:22

How to correctly write related rewrite conditions in nginx server settings?

Good afternoon.
Repeatedly tried to find answers on habré and documentation on nginx - alas, I did not find it.
The essence of the problem is that it is not clear whether it is possible to write something like this on nginx:

RewriteCond %{REMOTE_HOST}  ^host1.*  [OR]
RewriteCond %{REMOTE_HOST}  ^host2.*  [OR]
RewriteCond %{REMOTE_HOST}  ^host3.*
RewriteRule ...some special stuff for any of these hosts...

Having not found a solution in the summer, but I want to write a startup on a fast server, I wrote crutches based on the concatenation of operands in a condition like this
set $host_uri $host$request_uri;
if ($host_uri ~ bla-bla){
  rewrite ^(/(ru|en))(/.*) /community$3 last;
}

But this is obviously not a solution, and not even a solution to the first example.
Please help me figure it out, I spent a lot of time on finding out, in due time.
I read that someone with location also writes some crutches, but I didn’t understand how, because if one location grabs the link, then another location with forwarding to php-fpm will not work and php will not connect. Describing forwarding to php in each location is obviously not correct.
Now at least there is where to ask.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eugene, 2013-12-12
@Nc_Soft

Why can't it be resolved through the app?

N
Nikita Gusakov, 2013-12-12
@hell0w0rd

nothing is clear from your question.
It is clear that you want to optimize the huge colossus of Bitrix. Redirects - 5%, or even less, what is there to optimize?

E
Eugene, 2013-12-12
@Nc_Soft

Here's another thread for you :)
here it is

set $host_uri $host$request_uri;
if ($host_uri ~ bla-bla){
    rewrite ^(/(ru|en))(/.*) /community$3 last;
}

the mind does it
server {
    listen 80;
    server_name  host1.blabla.com; 
    location / {
          rewrite ^(/(ru|en))(/.*) /community$3 last;
    }
}
server {
    listen 80;
    server_name  host2.blabla.com; 
    location / {
          #другое правило итд
          rewrite ^(/(ru|en))(/.*) /community$3 last;
    }
}

Repeating blocks can be done through include.

E
evnuh, 2013-12-12
@evnuh

In a good way, of course, for each individual host (subdomain), you should start a separate server in nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question