lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

ngx.location.capture uses wrong certificate from a different server block

Open kai-li opened this issue 4 years ago • 7 comments

Hi,

I am using Nginx 1.19.5 with ngx_http_lua_module. We have been using ngx.location.capture().

Recently we use more server blocks. From the documentation, we expect subrequest is limited to the same server block. But what we have found is that when the set up is like below, the subrequest will randonly use a certificate from the other server block to fire a subrequest.

server {
  listen 11123 ssl;
  ..
  location /main {
    access_by_lua_block {
      ngx.location.capture("/sub")
    }
    proxy_pass https://www.testing.com;
  }
  location /sub {
    proxy_ssl_certificate crt-1.pem;
    proxy_ssl_certificate_key key-1.key;
    proxy_pass https://www.some-domain.com;
  }
} 

server {
  listen 11124 ssl;
  ..
  location /main {
     access_by_lua_block {
      ngx.location.capture("/sub")
    }
    proxy_pass https://www.testing.com;
  }
  location /sub {
    proxy_ssl_certificate crt-2.pem;
    proxy_ssl_certificate_key key-2.key;
    proxy_pass https://www.some-domain.com;
  }
} 

From the above setup. If the main request is using port 11123, the subrequest will sometimes use crt-2.pem instead of crt-1.pem, causing some issues.

Is this an expected behavior? is there any way to fix the issue? Any suggestions welcomed. Thank you!

kai-li avatar Nov 12 '21 20:11 kai-li

Do ports 11123 and 11124 have the same server_name?

zhuizhuhaomeng avatar Nov 14 '21 01:11 zhuizhuhaomeng

Yes. Both server blocks have _ as their server name. See below:

server_name _;

kai-li avatar Nov 14 '21 02:11 kai-li

try to add a different server name for each server. I think the location.capture did not consider the port.

zhuizhuhaomeng avatar Nov 14 '21 02:11 zhuizhuhaomeng

I have added a specific server name to one of the server block, and keeping the other one to use _, but the issue persists.

kai-li avatar Nov 16 '21 21:11 kai-li

http://nginx.org/en/docs/http/server_names.html `In catch-all server examples the strange name “_” can be seen:

server { listen 80 default_server; server_name _; return 444; } There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name. Other invalid names like “--” and “!@#” may equally be used.`

zhuizhuhaomeng avatar Nov 17 '21 01:11 zhuizhuhaomeng

so please try set specific names in both server

zhuizhuhaomeng avatar Nov 17 '21 01:11 zhuizhuhaomeng

Hi,

Sorry for the late reply. We tried that and the issue still exists.

kai-li avatar Apr 07 '22 16:04 kai-li