Tag Archives: Pagespeed

Nginx Pagespeed 404 file not found

Проблема: На клиенте не корректно отображается страницы сайта. Смотрим в Network – видим 404 Not Found на js и css, которые обработал pagespeed c фильтром combine_*

Link: Vendor  

Альтернативное решение: перенаправление на локальные файлы. Думаю, что это не правильный выход из ситуации. И не сработает с фильтрами pagespeed c фильтрами combine. Но имеет право на жизнь.

Перенаправление по 404 на локальные файлы

Link: Original

## Pagespeed optimized resources that returns 404, redirect to original resource
location ~ (.+)/x(.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
  # Handle resources with query string and Pagespeed optimized resources with 
  # file name prefixed with x (eg. xMyImage.png,qitok=qwer.pagespeed.asdf.webp)
  error_page 404 = @orig_resource;
  set $orig_resource_uri $1/$2?$3;
  try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
  # Handle resources with query string
  error_page 404 = @orig_resource;
  set $orig_resource_uri $1?$2;
  try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+)/x(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
  # Handle Pagespeed optimized resources with file name prefixed with x
  # (eg. xMyImage.png.pagespeed.asdf.webp)
  error_page 404 = @orig_resource;
  set $orig_resource_uri $1/$2;
  try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
  # Default handler
  error_page 404 = @orig_resource;
  set $orig_resource_uri $1;
  try_files $uri $uri/ $orig_resource_uri;
}
## Redirect Pagespeed optimized resources that returns 404 to 
## original resource.
location @orig_resource {
  return 302 $scheme://$server_name$orig_resource_uri;
}

[collapse]