微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。