首页 > 解决方案 > 需要 Nginx 专家(Wordpress 插件问题)

问题描述

我在 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 专家给我正确的重写配置并解决它!

提前致谢

标签: wordpressnginxnginx-locationnginx-config

解决方案


您的错误是您的所有图像请求都由 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;
}

推荐阅读