Очень часто видим, что у системных администраторов возникает сложность с настройкой продукта 1С-Битрикс с php-fpm, в интернете есть готовые конфигурации для nginx, но что делать, если требуется еще композитный сайт.
Замечу, что этот же конфиг отлично работает с https протоколом, просто у нас всегда есть распределение на nginx сервера для проксирования трафика по виртуальным площадкам и nginx сервер непосредственно на самой площадке. Как настроить https для проекта на 1С-Битрикс я подробно рассказал в статье: Полная инструкция по настройке HTTPS с оценкой А+
Делимся с вами файлом конфигурации, с которым у вас не должно возникнуть проблем в подключении композитного режима:
Конфигурационный файл domain.ru.conf:
server {
listen 80;
server_name domain.ru;
server_name_in_redirect off;
#access_log /var/log/nginx/domain.ru.acces.log;
error_log /var/log/nginx/domain.ru.error.log;
client_max_body_size 1024M;
client_body_buffer_size 4M;
root /var/www/domain.ru;
index index.php;
# Tehnical
# root /var/www/domain.ru/;
# index tehraboty.html;
set $frame_options '';
if ($http_referer !~ '^https?:\/\/([^\/]+\.)?(webvisor\.com)\/'){
set $frame_options 'SAMEORIGIN';
}
add_header X-Frame-Options $frame_options;
# Composit Bitrix
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"; }
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;
location / {
try_files $uri $uri/ @bitrix2;
}
location ~ \.php$ {
error_page 404 405 412 502 504 = @bitrix;
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;
}
location @bitrix {
include conf.d/fpm_settings.sub;
include fastcgi_params;
fastcgi_param HTTPS on;
fastcgi_pass backend;
}
location @bitrix2 {
include conf.d/fpm_settings.sub;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/bitrix/urlrewrite.php;
fastcgi_param HTTPS on;
fastcgi_pass backend;
}
location ^~ /bitrix/admin/.*\.php$ {
include conf.d/fpm_settings.sub;
include fastcgi_params;
fastcgi_param HTTPS on;
fastcgi_pass backend;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~* ^.+\.(jpg|jpeg|gif|png|webp|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|woff|woff2|ogv|mp4|webm)$ {
access_log off;
expires max;
add_header Cache-Control "public";
error_page 404 = /404.html;#не забываем создать страницу
}
location ~ (/\.ht|/bitrix/modules|/upload/support/not_image|/bitrix/php_interface|/\.svn|/\.git) {
deny all;
}
location /backup {
auth_basic "closed site";
auth_basic_user_file conf.d/htpasswd;
autoindex on;
sendfile on;
alias /opt/www/;
}
location ~ ^/(status|ping)$ {
access_log off;
auth_basic "closed site";
auth_basic_user_file conf.d/htpasswd;
include conf.d/fpm_settings.sub;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/bitrix/urlrewrite.php;
fastcgi_pass backend;
}
}
И файл fastcgi_params:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
Оригинальная статья https://onlinebd.ru/blog/1s-bitriks-nginx-php-fpm-kompozit