<div dir="ltr">Вот теперь до меня дошло. Спасибо.<br><br><div class="gmail_quote">2008/9/26 Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello!<div class="Ih2E3d"><br>
<br>
On Fri, Sep 26, 2008 at 01:11:31PM +0600, Rauan Maemirov wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Если хочется получить именно редирект, и при этом с хешированием по<br>
</blockquote>
ip-адресам - напишите простое хеширование на &gt;if&#39;ах/map&#39;ах, либо на<br>
встроенном perl&#39;е.<br>
<br>
Пытаюсь сделать на map&#39;ах. Но не пойму как написать &nbsp;&quot;простое хеширование на<br>
if&#39;ах/map&#39;ах&quot;. Так как у меня нужно редиректить только один location, map<br>
выдает ошибки...<br>
<br>
 &nbsp; map $uri $new {<br>
 &nbsp; &nbsp; &nbsp; /one &nbsp; <a href="http://site1.example.com/one/" target="_blank">http://site1.example.com/one/</a>;<br>
 &nbsp; &nbsp; &nbsp; /one &nbsp; <a href="http://site2.example.com/one/" target="_blank">http://site2.example.com/one/</a>;<br>
 &nbsp; }<br>
</blockquote>
<br></div>
А в чём смысл такой конструкции? &nbsp;Что, есть надежда что засовывание в ассоциативный массив двух значений с одним и тем же ключём приведёт к тому что они волшебным образом начнут возвращаться по очереди в зависимости от ip-адреса клиента и погоды на марсе? <br>

Мапы надо делать не на $uri, а на [части] ip. И потом использовать результат в rewrite. &nbsp;Как-то так:<br>
<br>
map $net $site {<br>
 &nbsp; &nbsp;0 &nbsp;1;<br>
 &nbsp; &nbsp;1 &nbsp;2;<br>
 &nbsp; &nbsp;2 &nbsp;1;<br>
 &nbsp; &nbsp;3 &nbsp;2;<br>
 &nbsp; &nbsp;...<br>
}<br>
<br>
location /one {<br>
 &nbsp; &nbsp;if ($remote_addr ~ &#39;^\d+\.\d+\.(\d+)&#39;) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;set $net $1;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;rewrite ^ <a href="http://site" target="_blank">http://site</a>$<a href="http://site.example.com/one" target="_blank">site.example.com/one</a>;<br>
 &nbsp; &nbsp;}<br>
}<br><font color="#888888">
<br>
Maxim Dounin</font><div><div></div><div class="Wj3C7c"><br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
2008/9/25 Maxim Dounin &lt;<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>&gt;<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello!<br>
<br>
On Thu, Sep 25, 2008 at 06:05:32PM +0600, Rauan Maemirov wrote:<br>
<br>
&nbsp;Здравствуйте.<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Помогите, пожалуйста, организовать редирект.<br>
<br>
В сервере <a href="http://example.com" target="_blank">example.com</a> есть апстрим.<br>
<br>
upstream site {<br>
 &nbsp; &nbsp; &nbsp;ip_hash;<br>
<br>
 &nbsp; &nbsp; &nbsp;server &nbsp; <a href="http://site1.example.com" target="_blank">site1.example.com</a>;<br>
 &nbsp; &nbsp; &nbsp;server &nbsp; <a href="http://site2.example.com" target="_blank">site2.example.com</a>;<br>
 &nbsp;}<br>
<br>
и есть location<br>
<br>
 &nbsp; &nbsp; &nbsp;location ^~ /one {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;proxy_pass &nbsp; &nbsp; <a href="http://site/one" target="_blank">http://site/one</a>;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;proxy_redirect default;<br>
 &nbsp; &nbsp; &nbsp;}<br>
<br>
Т.е. при обращении на <a href="http://example.com/one" target="_blank">example.com/one</a> он должен редиректиться на<br>
<a href="http://site1.example.com/one" target="_blank">site1.example.com/one</a> или <a href="http://site2.example.com/one" target="_blank">site2.example.com/one</a>. rewrite не подходит, так<br>
как мне нужен редирект с ip_hash.<br>
<br>
</blockquote>
<br>
Редирект - это возврат http-ответа 302 Found (либо 301, 307), его делает<br>
именно rewrite. &nbsp;То, что делает proxy_pass - это проксирование.<br>
<br>
Если хочется получить именно редирект, и при этом с хешированием по<br>
ip-адресам - напишите простое хеширование на if&#39;ах/map&#39;ах, либо на<br>
встроенном perl&#39;е.<br>
<br>
&nbsp;Получаю &quot;worker_connections is not enough while connecting to upstream&quot;<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
или<br>
&quot;no live upstreams while connecting to upstream&quot;.<br>
<br>
Насколько я понял, он зацикливается. Но никак не могу понять почему.<br>
<br>
</blockquote>
<br>
Судя по всему - <a href="http://site1.example.com" target="_blank">site1.example.com</a> и <a href="http://site2.example.com" target="_blank">site2.example.com</a> указывают на ту же<br>
машину, и при этом запрос попадает на обработку к тому же proxy_pass&#39;у и так<br>
далее - пока у nginx&#39;а не кончаться соединения.<br>
<br>
Maxim Dounin<br>
<br>
<br>
</blockquote></blockquote>
<br>
</div></div></blockquote></div><br></div>