我正在尝试代理图像服务器imagekit.io,以便所有请求都具有相同的域名。
已在HTTPS nginx服务器(具有自签名证书)甚至HTTP服务器中尝试了多种配置。
假设URL为https://ik.imagekit.io/hj8sm3kk7/brochures/92/1579/suzuki-gsx-r150-615123.pdf
[使用以下配置,我想点击http://localhost.com:8800/brochures/92/1579/suzuki-gsx-r150-615123.pdf
server {
listen 8800;
server_name localhost.com;
location /brochures {
proxy_ignore_headers Set-Cookie;
proxy_set_header Host ik.imagekit.io;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Pragma no-cache;
proxy_set_header Accept $http_accept;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Accept-Encoding $http_accept_encoding;
proxy_set_header Accept-Language $http_accept_language;
proxy_set_header sec-fetch-mode navigate;
proxy_set_header sec-fetch-site cross-site;
proxy_set_header sec-fetch-user ?1;
proxy_set_header :authority ik.imagekit.io;
proxy_set_header :method GET;
proxy_set_header :path $path;
proxy_set_header :scheme https;
proxy_set_header Upgrade-Insecure-Requests 1;
proxy_pass https://ik.imagekit.io/hj8sm3kk7/brochures;
}
}
但是这有效:
[http://localhost.com:8800/financial-advisor/mfs-investment-management-review打开与https://smartasset.com/financial-advisor/mfs-investment-management-review相同的页面
location /financial-advisor {
proxy_ignore_headers Set-Cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://smartasset.com;
}
真正的问题是ik.imagekit.io
的SSL问题,在http://
值中使用https://
而不是proxy_pass
很有帮助。
我给的原始(和错误)答案:
第一个示例需要对URL路径进行操作。考虑类似的方法:
location ~ ^/(brochures/.*) {
# all the previous config you used should be added here
proxy_pass https://ik.imagekit.io/hj8sm3kk7/$1;
}
这会将请求代理到正确的URL路径,该路径与原始请求不同。 $1
是请求URL路径中与前括号(...)
匹配的部分。