Response Header IF statement problem

webopsx nginx-forum at forum.nginx.org
Wed Feb 14 22:07:46 UTC 2018


Hi,

Yes NGINX can inspect the header, See the following full example. It will
check for the match of "true" case-insensitive. I am simulating your backend
on port 81. Does this make sense?

map $upstream_http_x_secured_page $nocache {
    ~*true                              "1";
    default                     "";
}

upstream backend {
    server 127.0.0.1:81;
}

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        proxy_no_cache $nocache;
        add_header X-No-Cache-Status $nocache;
        proxy_pass http://backend;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

server {

    listen 81;

    location / {
        add_header X-Secured-Page "True";
        return 200 "OK\n";
    }

}


# testing

root at dev:/etc/nginx/conf.d# curl -I localhost                               
                                                                            
                                                       
HTTP/1.1 200 OK
Server: nginx/1.13.7
Date: Wed, 14 Feb 2018 21:59:55 GMT
Content-Type: application/octet-stream
Content-Length: 3
Connection: keep-alive
X-Secured-Page: True
X-No-Cache-Status: 1

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278558,278578#msg-278578



More information about the nginx mailing list