OpenResty 配置文件,如何从上游变量读取 postgresql 连接信息?

问题描述

这是我的Nginx配置文件的一部分。我在我的本地JSON配置文件中定义了一些字段,并通过Nginx的标识符'init_lua_by_block'将这些字段读取为lua变量。我想将这些全局lua变量用于postgresql连接,但是不行!?有什么好的解决办法吗?

# init global variables
init_by_lua_block {
    engine_config_filename = "/usr/local/imagengine/engine/conf/localhost_configs.json";
    local config = require("init_config")
    local postgrersql_config = config.get_postgresql_config()
    postgresql_db = postgrersql_config.db
    postgresql_user = postgrersql_config.user
    postgresql_password = postgrersql_config.password
}

# Specifies the connection informations of Postgresql Database 
upstream pg_database {
    postgres_server 127.0.0.1 dbname=postgresql_db user=postgresql_user password=postgresql_password;
    postgres_keepalive max=800 mode=single overflow=ignore;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)