Giter Site home page Giter Site logo

In order to set the headers of the upstream request, I use `ngx.req.set_header` in `rewrite_by_lua_block`, but my upstream endpoint cannot receive such header. about lua-nginx-module HOT 5 OPEN

Hanoboo avatar Hanoboo commented on July 4, 2024
In order to set the headers of the upstream request, I use `ngx.req.set_header` in `rewrite_by_lua_block`, but my upstream endpoint cannot receive such header.

from lua-nginx-module.

Comments (5)

zhuizhuhaomeng avatar zhuizhuhaomeng commented on July 4, 2024

I don't know if proxy_pass_header helps.

from lua-nginx-module.

Hanoboo avatar Hanoboo commented on July 4, 2024

I don't know if proxy_pass_header helps.

It works,but I want to set the header dynamically in lua code.

from lua-nginx-module.

antpts avatar antpts commented on July 4, 2024

You should do something like this:

    upstream foo {
        server 127.0.0.1:6666 weight=1;
    }

    server {
        listen 8001;
        set $dynamicConnectionHeader ''; # default value
        location / {
            rewrite_by_lua_block {
                ngx.var.dynamicConnectionHeader = "Upgrade"
            }
            proxy_pass http://foo;
            proxy_set_header Connection $dynamicConnectionHeader;
        }
    }

    server {
        listen 8002;
        set $dynamicConnectionHeader 'Upgrade'; # default value
        location / {
            rewrite_by_lua_block {
                ngx.var.dynamicConnectionHeader = ""
            }
            proxy_pass http://foo;
            proxy_set_header Connection $dynamicConnectionHeader;
        }
    }

from lua-nginx-module.

Hanoboo avatar Hanoboo commented on July 4, 2024

You should do something like this:

    upstream foo {
        server 127.0.0.1:6666 weight=1;
    }

    server {
        listen 8001;
        set $dynamicConnectionHeader ''; # default value
        location / {
            rewrite_by_lua_block {
                ngx.var.dynamicConnectionHeader = "Upgrade"
            }
            proxy_pass http://foo;
            proxy_set_header Connection $dynamicConnectionHeader;
        }
    }

    server {
        listen 8002;
        set $dynamicConnectionHeader 'Upgrade'; # default value
        location / {
            rewrite_by_lua_block {
                ngx.var.dynamicConnectionHeader = ""
            }
            proxy_pass http://foo;
            proxy_set_header Connection $dynamicConnectionHeader;
        }
    }

The request header to be set is obtained dynamically through Lua and cannot be hard-coded with proxy_set_header.

from lua-nginx-module.

HanadaLee avatar HanadaLee commented on July 4, 2024

The connection header will be specially processed by nginx proxy (the default header value is "close"). You must use proxy_set_header to set the value of the connection header. You can use Lua to set other headers normally.

from lua-nginx-module.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.