Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Same content, different headers

$
0
0
I'm trying to configure nginx to achieve the following:

GET / -> returns index.html with additional header (e.g. X-ROOT = true)
GET /foo -> returns index.html with additiuonal header (e.g. X-FOO = true)
GET /v1/api/whatever -> everything which starts with /v1/api is passed to an upstream
GET /everything-else -> all the rest is served from disk, handled via try_files $url $url/ /index.html;

Below is my nginx.conf. All my responses contain the X-INDEX-HTML header. I have a vague idea why this is the case,
but I don't know the solution to have /foo return the contents of index.html with the X-FOO header.
Any help is appreciated.

server {
listen 80 default_server;

location /index.html {
add_header "X-INDEX-HTML" "true";

root /var/www/test;
try_files $uri $uri/ /index.html;
}

location = /foo {
add_header "X-FOO" "true";

root /var/www/test;
index /index.html;
}

location = / {
add_header "X-ROOT" "true";

root /var/www/test;
index /index.html;
}

location / {
root /var/www/test;
try_files $uri $uri/ /index.html;
}

location /v1/api/ {
proxy_pass http://my.upstream.net;
}
}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>