Openresty cookies whitelist when using proxy_pass

I’m setting up an openresty reverse proxy that will dispatch traffic to one of 2 backends depending on the path.

I would like certain cookies from backend1 not to be passed to backend2.

How should I do ?

Here is an my nginx.conf :

worker_processes 1;
error_log stderr;


events {
    worker_connections 1024;
http {
    resolver local=on;

    server {
        listen 80;

        root   /usr/share/nginx/html;
        include       /usr/local/openresty/nginx/conf/mime.types;
        set_by_lua $backend_url 'return os.getenv("BACKEND_URL")';
        set_by_lua $backend2_url 'return os.getenv("BACKEND2_URL")';

        location / {
            try_files $uri $uri/ /index.html;

        location ~ /backend/(.*)$ {
            proxy_pass $backend_url$1$is_args$args;

        location /backend2/ {
            access_by_lua_block {
            proxy_pass $backend2_url;

Go to Source
Author: Hedi