我创建了一个新堆栈,其中Nginx服务器充当CDN服务器和浏览器之间的反向代理,Nginx服务器应该解析来自CDN的所有HTML文件的SSI。问题是Nginx服务器只解决内容类型:text/html类型文件,而不是应用程序/八进制流(尽管所有这些文件都是实际的.html文件,尽管都是内容类型,但这是我们公司CDN上的一个小问题)。
location /path/ {
ssi on;
add_header Content-Type text/html;
proxy_pass https://example-cdn.com/path/;
}是否有办法强迫Nginx解析任何文件,只要扩展名是.html,尽管CDN响应中有内容类型的头文件?
发布于 2021-12-06 19:03:10
我在同一个配置中创建了一个辅助服务器,根据扩展重写了content,并从那里使用了主nginx服务器的内容。
配置相同的辅助服务器。
# Mapping
map $uri $custom_content_type {
default "application/octet-stream";
~(.*.json)$ "application/json";
~(.*.html)$ "text/html";
~(.*.pdf)$ "application/pdf";
}
server {
listen 8090;
server_name localhost;
location /path/ {
proxy_hide_header Content-Type;
add_header Content-Type $custom_content_type;
proxy_pass https://example-cdn.com/path/;
}
} 主服务器
location /path/ {
proxy_pass http://localhost:8090/path/;
}仍然需要一个更有效的解决方案。
https://stackoverflow.com/questions/70239953
复制相似问题