[QUOTE] написал:
[QUOTE][URL=/community/webdev/user/346607/]akazakov[/URL] написал:
[QUOTE] Иван Леонов написал:
[QUOTE] akazakov написал:
set $webp_suffix "";
if ($http_accept ~* "webp") {
set $webp_suffix ".webp";
}
location ~* \.(jpeg|jpg|png)$ {
add_header Vary "Accept-Encoding";
try_files $uri$webp_suffix $uri $uri/ =404;
#expires 30d;
}[/QUOTE]
CDN выключен, всё перепробовал, не получается подмена.
Вижу Response headers: "vary: Accept-Encoding", но картинка грузиться с расширением .png, а не .webp
Подскажите пожалуйста что делать?[/QUOTE]
Так в том то и смысл, что расширение остаётся тоже, но сам контент подменяется.
Смотрите в DevTools во вкладке Network колонку Type. Должно показывать webp, если конечно у файлов есть рядом лежащие .webp копии
[/QUOTE]
Здравствуйте! Такая же ситуация. Type везде jpeg... Если не сложно, прикрепите полное содержание файла /etc/nginx/bx/conf/bitrix_general.conf. Заранее спасибо!
Обновление
Получилось) Делюсь опытом. Вот что у меня сработало:
Скрипт .sh. Пригодится тем, у кого уже куча картинок в папке upload. Настройки сжатия можно выставить самостоятельно. Можно конечно и cron использовать.
Скрытый текст #!/usr/bin/env bash
# converting JPEG images
find /home/bitrix/ext_www/ vash site.ru /upload/ -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -q 90 "$0" -o "$webp_path";
fi;' {} \;
# converting PNG images
find /home/bitrix/ext_www/ vash site.ru /upload/ -type f -and -iname "*.png" \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -lossless "$0" -o "$webp_path";
fi;' {} \;
Внес изменения в файл /etc/nginx/bx/site_avaliable/bx_ext_ssl_vashsite.ru.conf / выделил красным новые строчки
Полное содержание файла
Скрытый текст # Ansible managed
#########################################################
# configuration for https-site:
# site_name: vashsite.ru
# site_root: /home/bitrix/ext_www/vashsite.ru
# site_composite: enable
# site_composite_id: 05
# site_composite_var: $is_site_composite_05
# site_composite_storage: files
# web_cluster: disable
##########################################################
server {
listen 443 http2;
server_name [URL=http://www.vashsite.ru]www.vashsite.ru[/URL] ;
return 301 $scheme://vashsite.ru$request_uri;
include bx/conf/site3.bx_ssl.conf;
}
server {
listen 443 http2;
server_name vashsite.ru;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|woff2|webp)$ {
if ( $http_accept ~* webp ) {
set $webp "A";
}
if ( $request_filename ~ (.+)\.(png|jpe?g)$ ) {
set $file_without_ext $1;
}
if ( -f $file_without_ext.webp ) {
set $webp "${webp}E";
}
if ( $webp = AE ) {
add_header Vary Accept;
rewrite ^(.+)\.(png|jpe?g)$ $1.webp break;
}
#Кеш - на ваше усмотрение
expires 365d;
}
access_log /var/log/nginx/vashsite.ru_access.log main;
error_log /var/log/nginx/vashsite.ru_error.log warn;
# Enable SSL connection
include bx/conf/site3.bx_ssl.conf;
set $docroot "/home/bitrix/ext_www/vashsite.ru ";
root "/home/bitrix/ext_www/vashsite.ru ";
proxy_ignore_client_abort off;
index index.php;
server_name_in_redirect off;
set $proxyserver " [URL=http://127.0.0.1:8887]http://127.0.0.1:8887"[/URL] ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:443;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header HTTPS YES;
if ($request_uri ~* "^(.*/)index\.php$") { return 301 [URL=https://$host$1]https://$host$1[/URL] ; }
if ($request_uri ~* "^(.*/)index\.html$") { return 301 [URL=https://$host$1]https://$host$1[/URL] ; }
set $imcontenttype "text/html; charset=utf-8";
add_header X-Frame-Options SAMEORIGIN;
# composite variables
set $composite_cache "bitrix/html_pages/${host}${composite_key}/index@${args}.html";
set $composite_file "${docroot}/${composite_cache}";
# config file
set $composite_enabled "${docroot}/bitrix/html_pages/.enabled";
# if test pass through general tests:
set $use_composite_cache "";
# global site test, the same for all sites on the server
if ($is_global_composite = 1) {set $use_composite_cache "A";}
# personal site tests, generated by site config
if ($is_site_composite_05 = 1) {set $use_composite_cache "${use_composite_cache}B";}
# Include parameters common to all websites
include bx/conf/bitrix_general.conf;
# main location with processing composite
location / {
if (-f $composite_enabled) { se t $use_composite_cache "${use_composite_cache}C"; }
# test cache file exists
if (-f $composite_file) { se t $use_composite_cache "${use_composite_cache}D"; }
if ($use_composite_cache = "ABCD") { rewrite .* /$composite_cache last; }
proxy_pass $proxyserver;
}
# Include munin and nagios web
include bx/server_monitor.conf;
}
Я так понимаю, что при очередном обновлении bitrix vm настройки не должны слететь. Или я не прав?)[/QUOTE]
Многократно использовал это решение. Но оказалось, что для картинок с русскоязычными названиями все равно отдается исходный файл.
dr.jpg заменяется на dr.webp, а вот др.jpg на др.webp - нет
Подскажите, как дописать условия, чтобы работало?
[QUOTE][URL=/community/webdev/user/346607/]akazakov[/URL] написал:
[QUOTE] Иван Леонов написал:
[QUOTE] akazakov написал:
set $webp_suffix "";
if ($http_accept ~* "webp") {
set $webp_suffix ".webp";
}
location ~* \.(jpeg|jpg|png)$ {
add_header Vary "Accept-Encoding";
try_files $uri$webp_suffix $uri $uri/ =404;
#expires 30d;
}[/QUOTE]
CDN выключен, всё перепробовал, не получается подмена.
Вижу Response headers: "vary: Accept-Encoding", но картинка грузиться с расширением .png, а не .webp
Подскажите пожалуйста что делать?[/QUOTE]
Так в том то и смысл, что расширение остаётся тоже, но сам контент подменяется.
Смотрите в DevTools во вкладке Network колонку Type. Должно показывать webp, если конечно у файлов есть рядом лежащие .webp копии
[/QUOTE]
Здравствуйте! Такая же ситуация. Type везде jpeg... Если не сложно, прикрепите полное содержание файла /etc/nginx/bx/conf/bitrix_general.conf. Заранее спасибо!
Обновление
Получилось) Делюсь опытом. Вот что у меня сработало:
Скрипт .sh. Пригодится тем, у кого уже куча картинок в папке upload. Настройки сжатия можно выставить самостоятельно. Можно конечно и cron использовать.
Скрытый текст #!/usr/bin/env bash
# converting JPEG images
find /home/bitrix/ext_www/ vash site.ru /upload/ -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -q 90 "$0" -o "$webp_path";
fi;' {} \;
# converting PNG images
find /home/bitrix/ext_www/ vash site.ru /upload/ -type f -and -iname "*.png" \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -lossless "$0" -o "$webp_path";
fi;' {} \;
Внес изменения в файл /etc/nginx/bx/site_avaliable/bx_ext_ssl_vashsite.ru.conf / выделил красным новые строчки
Полное содержание файла
Скрытый текст # Ansible managed
#########################################################
# configuration for https-site:
# site_name: vashsite.ru
# site_root: /home/bitrix/ext_www/vashsite.ru
# site_composite: enable
# site_composite_id: 05
# site_composite_var: $is_site_composite_05
# site_composite_storage: files
# web_cluster: disable
##########################################################
server {
listen 443 http2;
server_name [URL=http://www.vashsite.ru]www.vashsite.ru[/URL] ;
return 301 $scheme://vashsite.ru$request_uri;
include bx/conf/site3.bx_ssl.conf;
}
server {
listen 443 http2;
server_name vashsite.ru;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|woff2|webp)$ {
if ( $http_accept ~* webp ) {
set $webp "A";
}
if ( $request_filename ~ (.+)\.(png|jpe?g)$ ) {
set $file_without_ext $1;
}
if ( -f $file_without_ext.webp ) {
set $webp "${webp}E";
}
if ( $webp = AE ) {
add_header Vary Accept;
rewrite ^(.+)\.(png|jpe?g)$ $1.webp break;
}
#Кеш - на ваше усмотрение
expires 365d;
}
access_log /var/log/nginx/vashsite.ru_access.log main;
error_log /var/log/nginx/vashsite.ru_error.log warn;
# Enable SSL connection
include bx/conf/site3.bx_ssl.conf;
set $docroot "/home/bitrix/ext_www/vashsite.ru ";
root "/home/bitrix/ext_www/vashsite.ru ";
proxy_ignore_client_abort off;
index index.php;
server_name_in_redirect off;
set $proxyserver " [URL=http://127.0.0.1:8887]http://127.0.0.1:8887"[/URL] ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:443;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header HTTPS YES;
if ($request_uri ~* "^(.*/)index\.php$") { return 301 [URL=https://$host$1]https://$host$1[/URL] ; }
if ($request_uri ~* "^(.*/)index\.html$") { return 301 [URL=https://$host$1]https://$host$1[/URL] ; }
set $imcontenttype "text/html; charset=utf-8";
add_header X-Frame-Options SAMEORIGIN;
# composite variables
set $composite_cache "bitrix/html_pages/${host}${composite_key}/index@${args}.html";
set $composite_file "${docroot}/${composite_cache}";
# config file
set $composite_enabled "${docroot}/bitrix/html_pages/.enabled";
# if test pass through general tests:
set $use_composite_cache "";
# global site test, the same for all sites on the server
if ($is_global_composite = 1) {set $use_composite_cache "A";}
# personal site tests, generated by site config
if ($is_site_composite_05 = 1) {set $use_composite_cache "${use_composite_cache}B";}
# Include parameters common to all websites
include bx/conf/bitrix_general.conf;
# main location with processing composite
location / {
if (-f $composite_enabled) { se t $use_composite_cache "${use_composite_cache}C"; }
# test cache file exists
if (-f $composite_file) { se t $use_composite_cache "${use_composite_cache}D"; }
if ($use_composite_cache = "ABCD") { rewrite .* /$composite_cache last; }
proxy_pass $proxyserver;
}
# Include munin and nagios web
include bx/server_monitor.conf;
}
Я так понимаю, что при очередном обновлении bitrix vm настройки не должны слететь. Или я не прав?)[/QUOTE]
Многократно использовал это решение. Но оказалось, что для картинок с русскоязычными названиями все равно отдается исходный файл.
dr.jpg заменяется на dr.webp, а вот др.jpg на др.webp - нет
Подскажите, как дописать условия, чтобы работало?