Nginx:如何将Python脚本的结果发送给客户端?

问题描述 投票:0回答:1

我有一个简单的python脚本:生成器从提供给它的十六进制颜色生成x-icon,然后它返回有效的字节流(BytesIO)。

我想得到这样的东西(请不要笑,我使用Nginx大约两天了:]

location ~^/icons/(?<colour>[a-fA-F0-9]{6})\.ico$ {
    send 200 (./favicon.py colour); # System call to `favicon.py` with `colour` argument.
}

有可能吗?

python nginx system-calls nginx-location nginx-config
1个回答
0
投票

以下配置应完成该工作:

location ~^/icons/(?<colour>[a-fA-F0-9]{6})\.ico$ {
    content_by_lua '
        local command = "./favicon.py colour"
        local handle = io.popen(command)
        local content = handle:read("*a")
        handle:close()
        ngx.print(content)
    ';
}

基本上,它使用Lua执行和提供内容

注意:您的nginx应该使用lua模块进行编译,以使该解决方案有效”>

© www.soinside.com 2019 - 2024. All rights reserved.