Help for apply config nginx.conf with lua

122 views
Skip to first unread message

Thiago Duarte

unread,
Aug 24, 2023, 8:44:46 AM8/24/23
to openresty-en
Hello, I'm a beginner in this topic, but I need some help from you experienced people. I'm applying a configuration in a laboratory environment, but I'm not able to resolve the lack of the "resty.upstream" module below the file I'm trying to apply and in the sequence the log with the error shown:
========================================================================
[root@Traffic-Desktop-Openresty conf]# cat nginx.conf

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    resolver 8.8.8.8;
    include /usr/local/openresty-1.21.4.2/nginx/conf/mime.types;
    default_type application/octet-stream;
    log_format serverlog-live '$remote_addr - $host to: $stream_live $request $status $http_user_agent $http_x_forwarded_for';
#    lua_package_path "/usr/local/openresty-1.21.4.2/lualib/resty/upstream/?.lua;;";
    lua_package_path "/usr/local/openresty-1.21.4.2/modules/?.lua;;";

    lua_shared_dict healthcheck_statuses 1m;
    init_by_lua_block {
        local ok, upstream = pcall(require, "resty.upstream")
        if not ok then
            ngx.log(ngx.ERR, "Failed to require resty.upstream")
            return
        end
        local ok, hc = pcall(require, "resty.upstream.healthcheck")
        if not ok then
            ngx.log(ngx.ERR, "Failed to require resty.upstream.healthcheck")
            return
        end
        local hc_opts = {
            shm = "healthcheck_statuses",
            upstream = "backend",
        }
        local ok, err = hc.spawn_checker(hc_opts)
        if not ok then
            ngx.log(ngx.ERR, "Failed to spawn health checker: ", err)
            return
        end
    }
    upstream stream-live {
        server edgetier01-stream-live.atc.xxxxxxxx.com.br:80;
        server midtier01-stream-live.atc.xxxxxxxx.com.br:80;
    }
    upstream stream-cdvr {
        server edgetier01-stream-cdvr.atc.xxxxxxxx.com.br:80;
        server midtier01-stream-cdvr.atc.xxxxxxxx.com.br:80;
    }
    upstream stream-tstv {
        server edgetier01-stream-tstv.atc.xxxxxxxx.com.br:80;
        server midtier01-stream-tstv.atc.xxxxxxxx.com.br:80;
    }
    upstream stream-vod {
        server edgetier01-stream-vod.atc.xxxxxxxx.com.br:80;
        server midtier01-stream-vod.atc.xxxxxxxx.com.br:80;
    }
    server {
        listen 80;
        server_name nextrouter01-stream-http;
        location / {
            access_by_lua_block {
                local hc = require "resty.upstream.healthcheck"
                local ok, err = hc.status("backend", ngx.var.uri)
                if not ok then
                    ngx.log(ngx.ERR, "Failed to get health status: ", err)
                    return ngx.exit(500)
                end
                if ok then
                    local redirect_url = ngx.var.redirect_url
                    if redirect_url ~= "" then
                        return ngx.redirect(redirect_url, 302)
                    end
                end
                ngx.exit(503)
            }
        }
        location ~* ^/stream-live {
            set $stream_live stream-live;
            proxy_pass http://$stream_live;
            access_log /usr/local/openresty-1.21.4.2/nginx/logs/access.log serverlog-live;
        }
        location ~* ^/stream-cdvr {
            set $stream_cdvr stream-cdvr;
            proxy_pass http://$stream_cdvr;
        }
        location ~* ^/stream-tstv {
            set $stream_tstv stream-tstv;
            proxy_pass http://$stream_tstv;
        }
        location ~* ^/stream-vod {
            set $stream_vod stream-vod;
            proxy_pass http://$stream_vod;
        }
    }
}
============================================================================
Below is the error message when I start the openresty service:
[root@Traffic-Desktop-Openresty conf]# nginx -t
nginx: the configuration file /usr/local/openresty-1.21.4.2/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty-1.21.4.2/nginx/conf/nginx.conf test is successful
[root@Traffic-Desktop-Openresty conf]# /usr/local/openresty-1.21.4.2/nginx/sbin/nginx -s reload
Log information:
2023/08/24 08:41:57 [error] 197579#197579: [lua] init_by_lua(nginx.conf:24):4: Failed to require resty.upstream
2023/08/24 08:41:57 [error] 197579#197579: [lua] init_by_lua(nginx.conf:24):4: Failed to require resty.upstream
2023/08/24 08:41:57 [error] 197579#197579: [lua] init_by_lua(nginx.conf:24):4: Failed to require resty.upstream
2023/08/24 08:41:57 [notice] 197579#197579: using the "epoll" event method
2023/08/24 08:41:57 [notice] 197579#197579: using the "epoll" event method
2023/08/24 08:41:57 [notice] 197579#197579: start worker processes
2023/08/24 08:41:57 [notice] 197579#197579: start worker processes
2023/08/24 08:41:57 [notice] 197579#197579: start worker process 215384
2023/08/24 08:41:57 [notice] 197579#197579: start worker process 215384
2023/08/24 08:41:57 [notice] 215374#215374: gracefully shutting down
2023/08/24 08:41:57 [notice] 215374#215374: gracefully shutting down
2023/08/24 08:41:57 [notice] 215374#215374: exiting
2023/08/24 08:41:57 [notice] 215374#215374: exiting
2023/08/24 08:41:57 [notice] 215374#215374: exit
2023/08/24 08:41:57 [notice] 197579#197579: signal 17 (SIGCHLD) received from 215374
2023/08/24 08:41:57 [notice] 197579#197579: signal 17 (SIGCHLD) received from 215374
2023/08/24 08:41:57 [notice] 197579#197579: worker process 215374 exited with code 0
2023/08/24 08:41:57 [notice] 197579#197579: worker process 215374 exited with code 0
2023/08/24 08:41:57 [notice] 197579#197579: signal 29 (SIGIO) received
2023/08/24 08:41:57 [notice] 197579#197579: signal 29 (SIGIO) received

I appreciate the collaboration in who can guide on how to solve

BestRegards
Thiago

Igor Clark

unread,
Sep 4, 2023, 4:42:43 PM9/4/23
to openre...@googlegroups.com
Hi, might be a daft question but is the module definitely installed? Either with opm from https://opm.openresty.org/package/openresty/lua-resty-upstream-healthcheck/ or luarocks from https://luarocks.org/modules/hamish/lua-resty-upstream

cheers
i

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/ec83224e-190c-46e9-b52d-6032fe01a164n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages