Welcome! Log In Create A New Profile

Advanced

Same content, different headers

Posted by karel1980 
Same content, different headers
February 13, 2018 05:53AM
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;
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 255
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready