【问题标题】:Need Nginx Expert (Wordpress plugin issue)需要 Nginx 专家(Wordpress 插件问题)
【发布时间】:2020-03-09 11:42:05
【问题描述】:

我在 nginx 上运行一个 wordpress 网站,除了我的一个插件 = Adaptive Images for WordPress 之外,所有的工作都像一个魅力。 (此插件提供缩放图像)。

这个插件的所有者说,将它添加到位置,但它不起作用。

location / {
rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images-script.php;
}

也试过这个:

location ~ /wp-content/(themes|uploads) {
     rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images-script.php;
}

还有这个:

location ~ /wp-content/(themes|uploads) {
rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images-script.php;

}

没有任何效果!

这是我的 nginx 配置:https://github.com/stonedb00/stonedb/blob/master/nginxconf

所以我需要一位 nginx 专家来给我正确的重写配置并解决它!

提前致谢

【问题讨论】:

    标签: wordpress nginx nginx-location nginx-config


    【解决方案1】:

    你的错误是你所有的图片请求都由 nginx 处理这个location 块:

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires               60d;
        log_not_found         off;
    }
    

    由于您要使用插件处理所有图像请求,请尝试以下配置:

    location / {
        rewrite \.(?:jpe?g|gif|png)$ /wp-content/plugins/adaptive-images/adaptive-images-script.php last;
        try_files $uri $uri/ /index.php?$args;
    }
    
    # other locations here
    ...
    
    location ~* .(js|css|ico)$ {
        expires               60d;
        log_not_found         off;
    }
    

    【讨论】:

    • 感谢您抽出宝贵时间,Ivan,我已根据您的说明更新了我的配置。这是我的“新配置”:github.com/stonedb00/stonedb/blob/master/newnginxconf 但仍然无法正常工作,没有生成图像。如果您有其他建议...
    • 这个插件在“wp-content/cache/adaptive-images”中生成文件,这个目录还是空的。但是奇怪的是,当我转到sampledomain.com/wp-content/uploads/2019/11/… 时,它显示“您正在查看此页面而不是您请求的图像。这是自适应图像插件调试功能的一部分。看到这意味着插件运行正常......' 我认为 nginx conf 的问题已解决,我将联系插件所有者解决另一个问题。再次,非常感谢伊万!
    • 您可以尝试使用以下链接强制生成图像:www.sampledomain.com/wp-content//picture.png?resolution=640,1(使用任何真实的图像路径,您在管理页面上设置的任何分辨率)
    • 插件开发人员不能因为无法预见每个特殊情况而受到责备,例如使用 location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { ... } 增加某些文件类型的缓存时间 :) 在他的文档中唯一需要纠正的是将last 标志与rewrite 指令一起使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    相关资源
    最近更新 更多