Reputation: 63
I have create a new stack where Nginx server act as a reverse proxy between a CDN server and the browser, and the Nginx server supposed to resolve SSIs of all the HTML files from the CDN. The issue is Nginx server resolves only Content-type:text/html type files not application/octet-stream (even though all of them are actual .html files despite the content-type, it is a glitch on our company's CDN)
location /path/ {
ssi on;
add_header Content-Type text/html;
proxy_pass https://example-cdn.com/path/;
}
Is there a way to force Nginx to resolve any file as long as the extension is .html despite the Content-type header in the CDN response?
Upvotes: 1
Views: 535
Reputation: 63
I created a secondary server in the same config, rewriting the Content-Type based on the extension and consuming the content for the primary nginx server from there.
Secondary server in the same config
# 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/;
}
}
Primary server
location /path/ {
proxy_pass http://localhost:8090/path/;
}
still open for a more efficient solution.
Upvotes: 0