大网数据广告活动
服务器运维问答

Nginx proxy to Azure storage

· 52CE 我爱测

I am trying to setup an nginx reverse proxy for Azure blob storage. I'm using the nginx:1.13.9-alpine image, and I have a simple proxy_pass configured like this: location /container { proxy_pass https://account.blob.core.windows.…

问题原文

原帖链接 · superstator · CC BY-SA 3.0

I am trying to setup an nginx reverse proxy for Azure blob storage. I'm using the nginx:1.13.9-alpine image, and I have a simple proxy_pass configured like this:

location /container {
  proxy_pass              https://account.blob.core.windows.net/container;
  proxy_set_header        Host account.blob.core.windows.net  
}

However, it doesn't quite work. A direct request to the storage account works, so I know the SAS token is good:

curl -v "https://account.blob.core.windows.net/container/file?st=2018-04-02T01%3A57%3A00Z&se=2018-04-11T01%3A57%3A00Z&sp=rl&sv=2015-12-11&sr=b&sig=<sig>"

But using the same token through the proxy always returns a 403:

curl -v "https://proxy.mydomain.com/container/file?st=2018-04-02T01%3A57%3A00Z&se=2018-04-11T01%3A57%3A00Z&sp=rl&sv=2015-12-11&sr=b&sig=<sig>"
...snip...
< HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

In the server logs I just see:

10.240.0.4 - - [06/Apr/2018:04:07:30 +0000] "GET /container/file?st=2018-04-02T01%3A57%3A00Z&amp;se=2018-04-11T01%3A57%3A00Z&amp;sp=rl&amp;sv=2015-12-11&amp;sr=b&amp;sig=<sig> HTTP/1.1" 403 621 "-" "curl/7.54.0" "-"

I've seen some conflicting advice about needing to include $is_args, etc, but none of it seems to work. The same nginx instance proxies several other resources through other paths, all of which work as expected. What am I missing?

edit

I believe this is related to encoded characters like %2f in the url path. Azure Storage in this case is being used as the backend for a Docker Registry, and it likes to give blobs names like %2fdocker/registry/v2/blobs/sha256/e7/e7c1ef..ced394/data. If I add a sample blob in the container without the leading %2f, everything works as expected.

社区高分解答

原帖链接 · Sathish Kumar · CC BY-SA 4.0

In your default or site's config file. give blob container url as proxy_pass and set base url of your container as 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;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。