如果我有一个公共Azure Blob文件,例如https://mystorage.blob.core.windows.net/myblobcontainer/myblobpage.html
如果我想从自己的域名路由到该页面,我有哪些选择?
例如如果我想将mydomain.com/foo/blobpage
路由到上面的网址。
我知道可以使用Azure WebSites或CloudServices上的Web.confg来完成。 如此处所述Hide Azure Blob Url
还有其他选择吗?也许更轻量级? 我认为在Azure WebSite上使用配置会带来某种开销,也许某些nginx代理或某些东西可能会更有效。 那么有哪些替代方案以及它们在可扩展性方面与Web配置路由的比较如何?
答案 0 :(得分:1)
今天,通过Azure存储帐户,您可以配置自定义域名。 有关说明请参阅: https://azure.microsoft.com/en-us/documentation/articles/storage-custom-domain-name/
此外,如果询问的原因是自Web浏览器出现“同源策略”错误错误,您可以设置blob的CORS角色: https://msdn.microsoft.com/en-us/library/azure/dn535601.aspx
答案 1 :(得分:0)
我将研究的一个选项是使用HttpHandlers。
这是一个可以执行类似操作的示例处理程序:
using System;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
namespace WebApplication2
{
public class BlobProxy : IHttpHandler
{
// Please replace this with your blob container name.
const string blobContainerName = "files";
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
// Get the file name.
string fileName = context.Request.Path.Replace("/blobproxy/", string.Empty);
// Get the blob from blob storage.
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
var blobStorage = storageAccount.CreateCloudBlobClient();
string blobAddress = blobContainerName + "/" + fileName;
CloudBlob blob = blobStorage.GetBlobReference(blobAddress);
// Read blob content to response.
context.Response.Clear();
try
{
blob.FetchAttributes();
context.Response.ContentType = blob.Properties.ContentType;
blob.DownloadToStream(context.Response.OutputStream);
}
catch (Exception ex)
{
context.Response.Write(ex.ToString());
}
context.Response.End();
}
}
}
以下是注入Http Handler所需的配置:
<configuration>
<system.webServer>
<handlers>
<add name="BlobProxy" verb="*" path="/blobproxy/*" type="WebApplication2.BlobProxy"/>
</handlers>
</system.webServer>
</configuration>
答案 2 :(得分:0)
在默认或站点的配置文件中。将Blob容器网址设为proxy_pass
,并将容器的基本网址设为proxy_set_header Host
location /images {
proxy_pass https://YOURACCOUNT.blob.core.windows.net/images;
proxy_set_header Host YOURACCOUNT.blob.core.windows.net;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}