openresty / openresty/lua-nginx-module

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

Open
#1,970 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ngx.location.capture entry point and reproduce the configuration using the two server blocks on ports 11123 and 11124. Compare which proxy_ssl_certificate is selected for each subrequest and review the module's handling of server context. Done means the subrequest consistently uses the certificate from the originating server block, with the behavior verified for both ports.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.