【问题标题】:nginx as Apache front-end: how to redirect some image files?nginx 作为 Apache 前端:如何重定向一些图像文件?
【发布时间】:2021-10-31 18:07:08
【问题描述】:

我使用 nginx 作为 Apache 服务器的前端来提供静态文件,主要是这样的图像:

   location / {
   expires 15m;
   proxy_pass http://127.0.0.1:8080;
   }

  location ~* \.(jpg|gif|png|ico|svg)$ {
   expires 1M;
  }

问题:如何将一些图像文件永久重定向到新位置?

如果是 Apache,我会使用以下指令:

Redirect permanent /deleted_dir/some_image.gif                                     /image/some_image.gif
Redirect permanent /deleted_dir/other_image.gif                                    /image/new_image.jpg

我怎样才能用 nginx 做到这一点? 谢谢。

【问题讨论】:

    标签: apache nginx redirect


    【解决方案1】:

    最后,我发现 nginx “rewrite” 指令完成了这项工作:

            rewrite ^/deleted_dir/some_image.gif$     /image/some_image.gif permanent;
            rewrite ^/deleted_dir/other_image.gif$    /image/new_image.jpg permanent;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多