我将 Plesk 与 nginx + ModPagespeed + WordPress 结合使用

为了延迟加载图像,有一个占位符图像应该从这种 URL 加载 https://example.com/pagespeed_static/1.JiBnMqyl6S.gif它是动态的,没有实际的文件夹所以 WordPress 尝试将它发送到 index.php,因为在 nginx 中设置了这个 WordPress 规则:

if (!-e $request_filename) { 重写 ^(.+)$/index.php?q=$1 last; }

允许它加载图像的正确方法是什么?我是否应该检查 URL 是否等于该请求,然后在内部添加 WordPress 规则?

if($url != 'pagespeed_static/1.JiBnMqyl6S.gif') { 
   if (!-e $request_filename) {  
       rewrite ^(.+)$ /index.php?q=$1 last; 
   } 
} 

附言。刚刚注意到 .js 也有同样的问题,被 WordPress 相关规则捕获,URL 是 https://example.com/pagespeed_static/js_defer.I4cHjq6EEP.js

这里是 nginx 指令文件的内容:

# PAGESPEED - - - - - - - - - -  
 
pagespeed on; 
pagespeed FileCachePath /var/ngx_pagespeed_cache; 
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; } 
location ~ "^/pagespeed_static/" { } 
location ~ "^/ngx_pagespeed_beacon$" { } 
 
pagespeed CriticalImagesBeaconEnabled true; 
 
pagespeed PreserveUrlRelativity on; 
pagespeed InPlaceResourceOptimization off; 
pagespeed EnableFilters add_head; 
pagespeed EnableFilters combine_heads; 
pagespeed EnableFilters extend_cache; 
pagespeed EnableFilters inline_import_to_link; 
pagespeed EnableFilters outline_css; 
pagespeed EnableFilters outline_javascript; 
pagespeed EnableFilters remove_comments; 
pagespeed EnableFilters collapse_whitespace; 
pagespeed EnableFilters combine_css; 
pagespeed EnableFilters rewrite_css; 
pagespeed EnableFilters inline_css; 
pagespeed EnableFilters inline_google_fonts_css; 
pagespeed EnableFilters fallback_rewrite_css_urls; 
pagespeed EnableFilters rewrite_style_attribute; 
pagespeed EnableFilters rewrite_style_attributes_with_url; 
pagespeed EnableFilters flatten_css_imports; 
pagespeed EnableFilters prioritize_critical_css; 
pagespeed EnableFilters sprite_images; 
pagespeed EnableFilters rewrite_javascript; 
pagespeed EnableFilters combine_javascript; 
pagespeed EnableFilters inline_javascript; 
pagespeed EnableFilters defer_javascript; 
pagespeed EnableFilters inline_images; 
pagespeed EnableFilters recompress_images; 
pagespeed EnableFilters convert_png_to_jpeg; 
pagespeed EnableFilters resize_images; 
pagespeed EnableFilters convert_to_webp_lossless; 
pagespeed EnableFilters insert_image_dimensions; 
pagespeed EnableFilters inline_images; 
pagespeed EnableFilters jpeg_subsampling; 
pagespeed EnableFilters recompress_jpeg; 
pagespeed EnableFilters recompress_png; 
pagespeed EnableFilters recompress_webp; 
pagespeed EnableFilters lazyload_images; 
pagespeed LazyloadImagesAfterOnload off; 
pagespeed EnableFilters strip_image_color_profile; 
pagespeed EnableFilters strip_image_meta_data; 
pagespeed EnableFilters resize_images; 
pagespeed EnableFilters resize_rendered_image_dimensions; 
pagespeed EnableFilters inline_preview_images; 
pagespeed EnableFilters resize_mobile_images; 
pagespeed DisableFilters elide_attributes; 
pagespeed DisableFilters include_js_source_maps; 
pagespeed EnableFilters insert_dns_prefetch; 
 
# WORDPRESS - - - - - - - - - - - - - 
 
location ~ /\.ht { deny all; } 
location ~* wp-config.php { deny all; } 
location ~* "^/wp-content/(?!plugins/).*\.php" { deny all; } 
if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; } 

请您参考如下方法:

通过使用某些 plesk 支持页面上提出的另一种解决方案来解决。 所以不要使用

if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; } 

什么时候应该使用

if (!-e $request_filename) { set $test P; } 
if ($uri !~ ^/(pagespeed|plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon)) { set $test "${test}C"; } 
if ($test = PC) { rewrite ^/(.*)$ /index.php?$1; } 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!