提问人:BieberFantasy 提问时间:10/17/2023 最后编辑:BieberFantasy 更新时间:10/17/2023 访问量:16
通过域子目录向公众公开图像 API(Apache2,持有者令牌身份验证)
Exposing an image API to the public via a domain subdirectory (Apache2, bearer token authentication)
问:
我拥有一个从中间件检索图像的 API。它需要一个持有者令牌来进行人选化。此令牌存储在 .env 文件中。
我通过 Apache2 反向代理将其公开给 Internet(无需身份验证),并满足以下要求:
反向代理仅处理 .JPG 图像的 HTTP 请求。该后缀是固定的,区分大小写。
当用户请求 https://example.com/images/(path/to/image/)image.JPG 时,会向 http://api.example.com/a/b/(path/to/image/)image.JPG发出 API 请求。用户将收到来自 API 的响应,即使它是“未经授权”错误消息。希望它是JPEG。
https://example.com 提供 DocumentRoot 为 /var/www/html 的网站。没有 images 子目录,但即使有,也应该忽略它。
我笨拙地浏览了mod_apache文档,我正在理解如何同时实现上述所有目标。
下面的 Apache2 服务器配置不起作用,因为 <Proxy>
指令显然不能存在于 <LocationMatch>
指令中。但考虑到上述要求,它还有什么地方对我来说没有任何意义。
Apache 2.4.52 是否可以实现所有这些目标?如果是这样,我的理解中缺少什么?
提前致谢!
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
# Load environment variables from the .env file
SetEnvIf File "^/var/www/html/.env$" ^API_BEARER_TOKEN=(.*)
RequestHeader set Authorization "Bearer %{API_BEARER_TOKEN}e"
<LocationMatch "^/images/[^/]+\.JPG$">
<Proxy>
AuthType Bearer
AuthName "Bearer Token Authentication"
Require valid-user
</Proxy>
ProxyPassMatch http://api.example.com/a/b/$1
ProxyPassReverse http://api.example.com/a/b/
</LocationMatch>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
启用了以下 Apache 模组:
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
headers_module (shared)
mime_module (shared)
mpm_event_module (shared)
negotiation_module (shared)
proxy_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_html_module (shared)
proxy_http_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_shm_module (shared)
socache_shmcb_module (shared)
ssl_module (shared)
status_module (shared)
xml2enc_module (shared)
答: 暂无答案
评论