lua-resty-tencent-cos-signature
腾讯云 COS Openresty 请求签名授权头生成器
$ opm get mashirozx/lua-resty-tencent-cos-signature
lua-resty-tencent-cos-signature
概述
此库实现使用[腾讯云签名 XML 版本][docs]规范进行请求签名。我们可以使用此签名来请求 COS 中的对象并使用 Nginx(Openresty 或 lua-nginx-module)代理它们。
该库用于生成腾讯云 COS 对象存储的[请求签名 (XML 版本)][docs],因此可用于配置 Nginx(需要安装 Openresty 或编译 lua-nginx-module)反向代理私有仓库。
[docs]: https://cloud.tencent.com/document/product/436/7778#.E5.87.86.E5.A4.87.E5.B7.A5.E4.BD.9C
使用方法
此库使用环境变量作为凭据。
使用以下环境变量定义 ACCESS_KEY_ID
和 SECRET_ACCESS_KEY
。
export COS_ACCESS_KEY_ID=AKIDEXAMPLE
export COS_SECRET_ACCESS_KEY=AKIDEXAMPLE
为了在您的 nginx 配置中访问这些变量,这些变量应该在 nginx.conf
文件中声明。
之后还需要在 nginx.conf
中声明。
#user nobody;
worker_processes 1;
pid logs/nginx.pid;
env COS_ACCESS_KEY_ID;
env COS_SECRET_ACCESS_KEY;
# or specify them in Nginx config file only
#env COS_ACCESS_KEY_ID=AKIDEXAMPLE;
#env COS_SECRET_ACCESS_KEY=AKIDEXAMPLE;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
然后您可以使用该库向给定的 COS 存储桶添加 COS 签名头和 proxy_pass
。
之后就可以在 server 块中添加配置了。
server {
listen 80 default_server;
set $cos_bucket 'example-1200000000';
set $cos_host $cos_bucket.cos.ap-hongkong.myqcloud.com;
location / {
resolver 127.0.0.53 valid=300s;
resolver_timeout 10s;
rewrite (.*) /$1 break;
access_by_lua_block {
require("resty.cos-signature").cos_set_headers()
}
proxy_set_header Host $cos_host;
proxy_pass http://$cos_host;
}
}
安装
建议使用 OPM 安装脚本。
建议用 OPM 安装。
opm get mashirozx/lua-resty-tencent-cos-signature
贡献
查看 CONTRIBUTING.md 获取更多信息。
许可证
版权所有 2021 Mashiro
根据 Apache 许可证 2.0 版(“许可证”)授权; 除符合许可证条款外,您不得使用此文件。 您可以在以下网址获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或以书面形式同意,否则根据许可证分发的软件按“原样”分发,不附带任何明示或暗示的担保或条件。 请参阅许可证以了解管理权限和限制的特定语言。
作者
Mashiro (https://github.com/mashirozx)
许可证
apache2
依赖项
版本
-
腾讯云 COS Openresty 请求签名授权头生成器 2021-02-02 03:57:44