【问题标题】:nginx: decrypting a query paramnginx:解密查询参数
【发布时间】:2017-04-21 03:11:40
【问题描述】:

我有 2 台服务器。服务器 A 是运行 ASP.NET 的 Windows 服务器,服务器 B 是运行 Nginx 的 Linux 服务器。我需要将用户从服务器 A 安全地重定向到服务器 B。我想让服务器 A 将 ip=132.65.78.4;user=xyz@example.com;node=abc 之类的值加密为重定向的查询参数,如下所示:https://serverb.example.com?encrypted=<encrypted value here>

然后让服务器 B(使用共享密钥)解密查询参数,验证用户来自的 IP 地址,然后信任 usernode 的值来处理请求。

如何配置nginx 来执行此操作?我可以根据答案自己找出服务器 A 部分。谢谢!

【问题讨论】:

    标签: nginx


    【解决方案1】:

    我建议使用“nginx lua”模块,它可以让您使用 Lua 代码修改部分请求。

    那里有专门修改查询字符串的工具,因此您可以执行加密并设置“加密”值。

    https://github.com/openresty/lua-nginx-module#ngxreqset_uri_args

    如果您想处理请求参数,您可以通过set_by_lua_blockset_by_lua_file 进行此操作

    所以也许你可以这样做:

    set_by_lua_block $validated {
       local enc = ngx.var.arg_encrypted
       local decrypted = decrypt(enc)
    
       return do_some_validation(decrypted) and "1" or "0"
    }
    
    if ($validated = "0") {
       return 403;
    }
    

    【讨论】:

    • 谢谢!我的目标是让 nginx 端只需要解密加密的消息。我还会使用“nginx lua”吗?
    • 编辑了我的答案并提出了类似的建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 2017-01-18
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    相关资源
    最近更新 更多