Remove Cookie Nginx Proxy

39 views Asked by At

I have an nignx working as a reverse proxy, and i want to remove an specific cookie from the Cookies string sent in the request headers.

I have tried to make a regex filter to delete the cookie, and it works fine But when I try to set the modified cookie as the default cookie, it doesn't seem to be working, and the server still passes the initial http_cookie.

location /aaa/bbb/ccc{

   set $cookie2 $http_cookie;
    if ($http_cookie ~ '(.*)(^|;\s)COOKIE_REMOVED=("[^"]*"|[^\s]*[^;]?)(\2|$|;$)(?:;\s)?(.*)') {
        set $cookie2  $1$4$5;
    }

proxy_hide_header Cookie;
proxy_set_header  Cookie $cookie2 ;



    proxy_pass          http://{XXX};
    proxy_set_header    Host               $host;
    proxy_set_header    X-Real-IP          $remote_addr;
    proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Host   $host;
    proxy_set_header    X-Forwarded-Server $host;
    proxy_set_header    X-Forwarded-Port   $server_port;
    proxy_set_header    X-Forwarded-Proto  $scheme;
}

Does anyone know what could be wrong?

0

There are 0 answers