Re: Применение директивы для определенного IP адреса

2016-10-23 Thread maxpostal
Спасибо!

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?21,270039,270497#msg-270497

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Rewrite Vary header before stored in proxy_cache

2016-10-23 Thread Lucas Rolff
Hi guys,

I'm building a small nginx reverse proxy to take care of a bunch of static
files for my clients - and it works great.

One thing I'm facing though is that some client sites sent "Vary:
Accept-Encoding, User-Agent" - which gives an awful cache hit rate - since
proxy_cache takes this into account, unless I use something like
"proxy_ignore_headers Vary;"

But ignoring Vary headers can cause other issues such as gzipped content
being sent to a non-gzip client.

So I'm looking for a way to basically rewrite the vary header to "Vary:
Accept-Encoding" before storing it in proxy_cache - but I wonder if this is
even possible in nginx, and if yes - can you give any pointers?

I found a temporary fix, and that is to ignore the Vary header, and using a
custom variable as a part of the cache key, that is either "", "gzip" or
"deflate" (I use a map to look at the Accept-Encoding header from the
client).

This works great - but I rather keep the cache key a bit clean (since I'll
use it later)

Do you guys have any recommendations how to make this happen?

Also as a side note, if I remove the custom variable from the cache key,
how would one actually purge the file then? I assume I have to send
different purge requests, since the cached file is based on the Vary:
accept-encoding - so I'd have to purge at least the amount of cached
encodings right?

Also I could opt for another way, and that's always requesting a
uncompressed file from the origin (Is it simply not sending the
accept-encoding header, or should I do something else?), and then on every
request either decide to gzip it or not - the downside I see here, is the
fact that most clients request gzip,deflate content, so having to compress
on every request will use additional CPU resources.

Thanks in advance!

--
Best regards,
Lucas Rolff
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Применение директивы для определенного IP адреса

2016-10-23 Thread Oleg A. Mamontov
On Sun, Oct 23, 2016 at 03:52:58PM -0400, maxpostal wrote:
> Почитал http://nginx.org/ru/docs/http/ngx_http_map_module.html, спасибо.
> 
> То есть код:
> 
> map $http_x_forwarded_for $key {
>   5.187.78.183 1;
> }
> 
> создает новую переменную $key и если значение текущего IP клиента -
> $http_x_forwarded_for соответствует нужному IP-адресу - 5.187.78.183, то
> переменной $key присваивается значение 1?
> 
> и соответственно лимиты:
> limit_req_zone $key zone=perserver:10m rate=1r/s;
> limit_conn_zone $key zone=perip:10m;
> 
> будут использоваться только для этого IP, для всех других $key будет
> пустым.
> 
> А как же сделать, чтобы этот IP выступал в виде исключения?

map $http_x_forwarded_for $key {
5.187.78.183 '';
default $http_x_forwarded_for;
}

> Может так?
> 
> if (!$key) {
>   limit_req_zone $binary_remote_addr zone=perserver:10m rate=1r/s;
>   limit_conn_zone $binary_remote_addr zone=perip:10m;
> }
> 
> Posted at Nginx Forum: 
> https://forum.nginx.org/read.php?21,270039,270493#msg-270493
> 
> ___
> nginx-ru mailing list
> nginx-ru@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-ru

-- 
Cheers,
Oleg A. Mamontov

mailto: o...@mamontov.net

skype:  lonerr11
cell:   +7 (903) 798-1352

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: Применение директивы для определенного IP адреса

2016-10-23 Thread maxpostal
Почитал http://nginx.org/ru/docs/http/ngx_http_map_module.html, спасибо.

То есть код:

map $http_x_forwarded_for $key {
  5.187.78.183 1;
}

создает новую переменную $key и если значение текущего IP клиента -
$http_x_forwarded_for соответствует нужному IP-адресу - 5.187.78.183, то
переменной $key присваивается значение 1?

и соответственно лимиты:
limit_req_zone $key zone=perserver:10m rate=1r/s;
limit_conn_zone $key zone=perip:10m;

будут использоваться только для этого IP, для всех других $key будет
пустым.

А как же сделать, чтобы этот IP выступал в виде исключения?

Может так?

if (!$key) {
  limit_req_zone $binary_remote_addr zone=perserver:10m rate=1r/s;
  limit_conn_zone $binary_remote_addr zone=perip:10m;
}

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?21,270039,270493#msg-270493

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: настройка systemd в centos 7

2016-10-23 Thread SK
Nginx не может проверить возможность забиндиться на адрес, пока адрес 
отсутствует. Выглядит логично. 

При необходимости изменить поведение, емнип был рычажок, позволяющий биндиться 
на нелокальный адрес. Но лично не проверял.

Или баг в отсутствии указанной зависимости в офисборке? Тогда наверное 
соглашусь...

SK

> 23 окт. 2016 г., в 18:46, Илья Шипицин  написал(а):
> 
> Добрый день!
> 
> не стартовал nginx из официального репозитория
> при запуске системы падает с ошибкой
> 
> Oct 23 20:43:49 vm-14c6d53b nginx[571]: nginx: [emerg] bind() to X.X.X.X:80 
> failed (99: Cannot assign requested address)
> 
> поменял в /lib/systemd/system/nginx.service:
> 
> 
> After=network-online.target
> 
> 
> стало запускаться при старте.
> 
> чем-то обусловлена зависимость именно от network.target ?
> похоже на баг
> 
> Илья Шипицин
> ___
> nginx-ru mailing list
> nginx-ru@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-ru

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: настройка systemd в centos 7

2016-10-23 Thread Илья Шипицин
именно

воскресенье, 23 октября 2016 г. пользователь SK написал:

> Подозреваю, в listen указан конкретный адрес?
>
> SK
>
> > 23 окт. 2016 г., в 18:46, Илья Шипицин  > написал(а):
> >
> > Добрый день!
> >
> > не стартовал nginx из официального репозитория
> > при запуске системы падает с ошибкой
> >
> > Oct 23 20:43:49 vm-14c6d53b nginx[571]: nginx: [emerg] bind() to
> X.X.X.X:80 failed (99: Cannot assign requested address)
> >
> > поменял в /lib/systemd/system/nginx.service:
> >
> >
> > After=network-online.target
> >
> >
> > стало запускаться при старте.
> >
> > чем-то обусловлена зависимость именно от network.target ?
> > похоже на баг
> >
> > Илья Шипицин
> > ___
> > nginx-ru mailing list
> > nginx-ru@nginx.org 
> > http://mailman.nginx.org/mailman/listinfo/nginx-ru
>
> ___
> nginx-ru mailing list
> nginx-ru@nginx.org 
> http://mailman.nginx.org/mailman/listinfo/nginx-ru
___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: настройка systemd в centos 7

2016-10-23 Thread SK
Подозреваю, в listen указан конкретный адрес?

SK

> 23 окт. 2016 г., в 18:46, Илья Шипицин  написал(а):
> 
> Добрый день!
> 
> не стартовал nginx из официального репозитория
> при запуске системы падает с ошибкой
> 
> Oct 23 20:43:49 vm-14c6d53b nginx[571]: nginx: [emerg] bind() to X.X.X.X:80 
> failed (99: Cannot assign requested address)
> 
> поменял в /lib/systemd/system/nginx.service:
> 
> 
> After=network-online.target
> 
> 
> стало запускаться при старте.
> 
> чем-то обусловлена зависимость именно от network.target ?
> похоже на баг
> 
> Илья Шипицин
> ___
> nginx-ru mailing list
> nginx-ru@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-ru

___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Re: Применение директивы для определенного IP адреса

2016-10-23 Thread Иван
В письме от 22 октября 2016 10:50:41 пользователь maxpostal написал:
>  #map $http_x_forwarded_for $binary_remote_addr {
> #   5.187.78.183 1;
> #}
> #limit_req_zone $binary_remote_addr zone=perserver:10m rate=1r/s;
> #limit_conn_zone $binary_remote_addr zone=perip:10m;
Закомментированный код измените дословно (не надо ни на что заменять $key!) 
на:
 map $http_x_forwarded_for $key {
   5.187.78.183 1;
}
limit_req_zone $key zone=perserver:10m rate=1r/s;
limit_conn_zone $key zone=perip:10m;

Тогда лимиты будут применены для всех с данным значением $key. Чтоб лимиты не 
применялись, значение $key должно быть пустым. Прочитайте, пожалуйста, 
описание map в документации, тогда станет понятнее.
___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

настройка systemd в centos 7

2016-10-23 Thread Илья Шипицин
Добрый день!

не стартовал nginx из официального репозитория
при запуске системы падает с ошибкой

Oct 23 20:43:49 vm-14c6d53b nginx[571]: nginx: [emerg] bind() to X.X.X.X:80
failed (99: Cannot assign requested address)

поменял в /lib/systemd/system/nginx.service:


After=network-online.target


стало запускаться при старте.

чем-то обусловлена зависимость именно от network.target ?
похоже на баг

Илья Шипицин
___
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru