Почему: не удалось запустить balancer_by_lua*: balancer_by_lua:2: loop или предыдущая ошибка загрузки модуля 'ngx.balancer'

Почему localhost:7000 всегда возвращает «500 Internal Server Error».

      

#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;

load_module modules/ndk_http_module.so;  # assuming NDK is built as a dynamic module too
load_module modules/ngx_http_lua_module.so;
load_module modules/ngx_stream_lua_module.so;

events {
    worker_connections  1024;
}



http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    lua_package_path  "/usr/local/lib/lua/?.lua;;";
    
    upstream backend {
        server 0.0.0.1;   # just an invalid address as a place holder

        balancer_by_lua_block {
            local balancer = require "ngx.balancer"

            -- well, usually we calculate the peer's host and port
            -- according to some balancing policies instead of using
            -- hard-coded values like below
            local host = "127.0.0.1"
            local port = 8080

            local ok, err = balancer.set_current_peer(host, port)
            if not ok then
                ngx.log(ngx.ERR, "failed to set the current peer: ", err)
                return ngx.exit(500)
            end
        }

        keepalive 10;  # connection pool
    }

    server {
        # this is the real entry point
        listen 80;

        location / {
            # make use of the upstream named "backend" defined above:
            proxy_pass http://backend/fake;
        }
    }

    server {
        # this server is just for mocking up a backend peer here...
        listen 127.0.0.1:8080;

        location = /fake {  
            content_by_lua_block {
            ngx.say "this is the fake backend peer...";
            }
            
            
        }
    }
}

Я пытаюсь установить скрипт Nginx и Lua, но всегда получаю сообщение об ошибке, когда хочу использовать ngx.balancer, вот ошибка:
2021/09/12 20:00:05 [ошибка] 37014 # 0: 20 не удалось запустить balancer_by_lua : balancer_by_lua: 2: цикл или предыдущая ошибка загрузки модуля 'ngx.balancer', трассировка стека: [C]: в функции 'require' balancer_by_lua: 2: в основном блоке при подключении к восходящему потоку, клиент: 127.0.0.1, сервер:, запрос : "GET / HTTP / 1.1", хост: "localhost"

0 ответов

Другие вопросы по тегам