openresty / openresty/lua-nginx-module

nginx proxy_pass ssl handshake error

Open
#1,703 1 comment 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

  • OpenResty version is
    nginx version: openresty/1.15.8.2

  • Hi, I am new to nginx lua scripting and I am trying to write a small script based on the user request, the script queries the redis server and fetches the key based on the uri

  • This nginx server is running behind a envoyproxy

  • For example: If user requests for https://test.example.com/345678
    lua script queries redis for key 345678 and fetches the file path which is /root/test/test.mpd
    this files should be then served by nginx to the user

This is my lua script

server {
        root /root/test;
        index index.html;
        server_name test.example.com;
	absolute_redirect off;
        location ~ ^/(.*?)/?$ {
	resolver 8.8.4.4;
	server_tokens off;
        default_type 'text/plain';
	set $target "";
        access_by_lua '
                    local redis = require "resty.redis"
		    local key1 = ngx.var.request_uri
		    local key2 = ngx.var.host..key1
                    local red = redis:new()
                    red:set_timeout(1000)
                    local ok, err = red:connect("10.0.0.1", 6379)
                    if not ok then
                        ngx.say("failed to connect: ", err)
                        return
                    end
		    local res, err = red:auth("testauth")
    		    if not res then
                      ngx.say("failed to authenticate: ", err)
                      return
                    end
	            local host, err = red:get(key2)
	            if not host then
                    	ngx.say("failed to get redis key: ", err)
		        return ngx.exit(500)
                    end
		    if host == ngx.null then
		        ngx.say("no value found for key ", key2)
                        return ngx.exit(400)
                    end
	        ngx.var.target = host
         ';
	proxy_pass https://test.example.com$target;
        }
}
  • this is my nginx error log
    2020/05/06 12:30:20 [error] 938#938: *249 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 10.0.0.0, server: test.example.com, request: "GET /345678 HTTP/1.1", upstream: "https://8.9.9.9:443/test/test.mpd/, host: "test.example.com"

  • expected behaviour was getting the response 200 and serving the actual file path to the request

  • output curl -s https://test.example.com/345678
    I got 502 bad gateway error

<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty</center>
</body>
</html>

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 inline nginx server configuration, especially the access_by_lua block and proxy_pass directive, then review the reported upstream SSL handshake error. Reproduce the request with curl and compare the upstream log details; done means the mapped request returns HTTP 200 and serves the expected file instead of a 502.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx, redis
Domain
backend, networking
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.