Score:0

Why can not modify the value in nginx.conf

US flag

I have a map in nginx.conf,

stream {
    upstream s1{
        server 127.0.0.1:670;
    }
    upstream s2{
        server 127.0.0.1:680;
    }

    map $symbol_key $symbol_value{
        c1 s1;
        c2 s2;
    }
    server {
        set $symbol_key "c1";
        set $symbol_value "s1";
        listen 66;
        proxy_pass $symbol_value;
    }

}

If I delete map, the request can be routed to s2 after I set symbol_value to s2. But I want to decide router throw symbol_key, if I use the map, no matter which value(c1 or c2) I set to symbol_key, request will always be routed to s1.

I modify the value in phases[NGX_STREAM_PREREAD_PHASE].handlers like this

ngx_str_t str1 = ngx_string("symbol_key");
ngx_uint_t key = ngx_hash_key(str1.data, str1.len);
ngx_stream_variable_value_t *vv = ngx_stream_get_variable(s, &str1, key);
ngx_str_t str2 = ngx_string("c2");
vv->data = str2.data;
vv->len = str2.len;
ngx_log_error(NGX_LOG_ERR, c->log, 0, "after set");

Why can not the request be routed to s2?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.