10  /  26

Настройки NGINX в других окружениях

Просмотров: 56340
Дата последнего изменения: 17.01.2024
Роберт Басыров
Сложность урока:
2 уровень - несложные понятия и действия, но не расслабляйтесь.
1
2
3
4
5
Недоступно в лицензиях:
Ограничений нет

  Настройки

Композитный кеш можно отдавать через PHP или NGINX. В первом случае никаких дополнительных настроек делать не надо, все сделает сам продукт, во втором случае требуется дополнительная настройка сервера NGINX. Настройки сервера производятся по аналогии с настройками сервера в виртуальной машине BitrixVM.

Ниже приведены настройки для версий "1С-Битрикс: Управление сайтом" до версии 16.0.14 (до появления Автокомпозита).

При хранении в файлах:

#### user defined variables
# document root
root /home/bitrix/www;

# apache|php-fpm upstream
set $backend "127.0.0.1:8080";
#### /user defined variables

# default path to cache file
set $test_file "/bitrix/html_pages/$host$uri/index@$args.html";
set $storedAuth "";
set $usecache "";

# check all conditions for enable composite
if ( $http_bx_action_type = "" )     { set $usecache "A"; }
if ( $request_method = "GET" ) { set $usecache "${usecache}B"; }
if ( $cookie_BITRIX_SM_NCC = "" ) { set $usecache "${usecache}C"; }
if ( $http_x_forwarded_scheme !~ "https" ){ set $usecache "${usecache}D"; }

# IE9 and above exclude
modern_browser_value "modern";
modern_browser msie 10.0;
modern_browser unlisted;
if ($modern_browser) {
   set $usecache "${usecache}E";
}

# check user auth
if ( $cookie_BITRIX_SM_LOGIN != "" ) { set $storedAuth "A"; }
if ( $cookie_BITRIX_SM_UIDH != "" ) { set $storedAuth "${storedAuth}B"; }
if ( $cookie_BITRIX_SM_CC != "Y" ) { set $storedAuth "${storedAuth}C"; }
if ( $storedAuth !~ "ABC" ) { set $usecache "${usecache}F"; }

## cache location
location ~* @.*\.html$ {
   internal;
}

# use default cache file
location / {
   if ($usecache != "ABCDEF" ) { proxy_pass http://$backend; }
   try_files $test_file @apache;
}

# use own path to cache file: test_file
location ~* ^(.*)\.php$ {
   set $test_file "/bitrix/html_pages/$host$1@$args.html";
   if ($usecache != "ABCDEF" ) { proxy_pass http://$backend; }
   try_files $test_file @apache;
}

# apache location
location @apache {
   proxy_pass http://$backend;
}

При хранении в memcached:

#### user defined variables
# document root
root /home/bitrix/www;

# apache|php-fpm upstream
set $backend "127.0.0.1:8080";
#### /user defined variables

set $storedAuth "";
set $usecache "";

# check all conditions for enable composite
if ( $http_bx_action_type = "" )     { set $usecache "A"; }
if ( $request_method = "GET" ) { set $usecache "${usecache}B"; }
if ( $cookie_BITRIX_SM_NCC = "" ) { set $usecache "${usecache}C"; }
if ( $http_x_forwarded_scheme !~ "https" ){ set $usecache "${usecache}D"; }
if ( $http_accept_encoding ~* "deflate" ){ set $usecache "${usecache}E"; }

# IE9 and above exclude
modern_browser_value "modern";
modern_browser msie 10.0;
modern_browser unlisted;
if ($modern_browser) {
   set $usecache "${usecache}F";
}

# check user auth
if ( $cookie_BITRIX_SM_LOGIN != "" ) { set $storedAuth "A"; }
if ( $cookie_BITRIX_SM_UIDH != "" ) { set $storedAuth "${storedAuth}B"; }
if ( $cookie_BITRIX_SM_CC != "Y" ) { set $storedAuth "${storedAuth}C"; }
if ( $storedAuth !~ "ABC" ) { set $usecache "${usecache}G"; }

memcached_connect_timeout 1s;
memcached_read_timeout 1s;
memcached_send_timeout 1s;

# use default cache file
location / {
   error_page 404 405 412 502 504 = @apache;
   if ($usecache != "ABCDEFG" ) { return 412; }

   default_type text/html;
   set $memcached_key "/$host$uri@$args.html";
   if ($uri ~ "/$")
   {
      set $memcached_key "/$host${uri}index@$args.html";
   }

   add_header Content-Encoding deflate;
   memcached_pass localhost:11211;
}

location ~* ^(.*)\.php$ {
   error_page 404 405 412 502 504 = @apache;
   if ($usecache != "ABCDEFG" ) { return 412; }

   default_type text/html;
   set $memcached_key "/$host$1@$args.html";
   add_header Content-Encoding deflate;
   memcached_pass localhost:11211;
}

# apache location
location @apache {
   proxy_pass http://$backend;
}

  Видео

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


15
Курсы разработаны в компании «1С-Битрикс»

Если вы нашли неточность в тексте, непонятное объяснение, пожалуйста, сообщите нам об этом в комментариях.
Развернуть комментарии