1

我在 Amazon S3 上托管我的图像并且只存储一种图像大小。

到目前为止,我已经成功地使用Imageresizer来根据请求调整我的图像大小。

现在我需要介绍 Cloudfront CDN,这给我带来了困难。

我已经按照文档设置了我的配置。

像这样:

<resizer>
    <diskcache dir="~/app_data" autoClean="true"/>
    <clientcache minutes="1440"/>
    <cloudfront redirectThrough="http://cdn.example.com" redirectPermanent="false"/>
    <plugins>
      <add name="DiskCache"/>
      <add name="ClientCache"/>
      <add name="MvcRoutingShim"/>
      <add name="CloudFront"/> 
    </plugins>
  </resizer>

然后我捕获到我的应用程序的任何 URL,如下所示:

private static void ImageResizer_OnPostAuthorizeRequestStart(
    IHttpModule sender2, HttpContext context)
{
    string path = Config.Current.Pipeline.PreRewritePath;
    if (!path.StartsWith(PathUtils.ResolveAppRelative("~/cdn/"),
        StringComparison.OrdinalIgnoreCase))
    {
        return;
    }

    Config.Current.Pipeline.SkipFileTypeCheck = true;
    Config.Current.Pipeline.ModifiedQueryString["cache"]
        = ServerCacheMode.Always.ToString();
}

以便 Imageresizer 可以处理它们。

当它这样做时,它将更改我的 URL 以使用正确的 CDN 路径,但它也会将查询字符串参数更改为分号:

http://example.com/cdn/image.jpg?mode=crop&width=200

对此:

http://mycdn.example.com/image.jpg;mode=crop;width=200

不幸的是,Amazon S3 不喜欢这样,并将其作为拒绝访问而踢出。然而,亚马逊很乐意为原始查询字符串提供服务。

那么,如何保留查询字符串以防止 Imageresizer 将参数更改为分号?

或者配置 amazon,以便无论分号如何,它都会提供图像?

4

1 回答 1

1

您不使用 CloudFront而不是S3,而是同时使用它们。您的云端分发应指向运行 ImageResizer 的服务器,该服务器又使用 S3Reader 访问 Amazon S3。CloudFront 不应直接指向 S3;这将从图片中消除 ImageResizer。

请参阅http://imageresizing.net/docs/cloud

于 2013-02-02T20:24:11.997 回答