我用OpenResty用MFA创建了代理,它主要工作正常。
但是我对websockets有问题: Firefox说它“无法连接到服务器wss://...”。查看浏览器的网络面板,我可以看到切换协议请求似乎是正常的。我的nginx.conf看起来像下面这样:
worker_processes auto;
env TARGET_APPLICATION_HOST;
env TARGET_APPLICATION_PORT;
env TARGET_USE_SSL;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location / {
resolver local=on ipv6=off valid=100s;
content_by_lua_block {
local http = require "resty.http"
local httpc = http.new()
httpc:set_timeout(500)
local ok, err = httpc:connect(
os.getenv("TARGET_APPLICATION_HOST"),
os.getenv("TARGET_APPLICATION_PORT"))
if not ok then
ngx.log(ngx.ERR, err)
return
end
if os.getenv("TARGET_USE_SSL") == "TRUE" then
-- Trigger the SSL handshake
session, err = httpc:ssl_handshake(False, server, False)
end
httpc:set_timeout(2000)
httpc:proxy_response(httpc:proxy_request())
httpc:set_keepalive()
}
}
}
}它是production proxy的简单版本,但会返回与websockets相同的错误。我尝试使用代理与纯nginx和它的工作与websockets,但我需要OpenResty的功能(代理不同的主机基于Cookie值)。
上面的文件有没有什么简单的错误或者OpenResty没有websocket功能?
发布于 2021-04-27 18:05:22
lua-resty-http是一个超文本传输协议(S)客户端库,它不(也可能不会)支持WebSocket协议。
还有另一个用于WebSocket协议的库:lua-resty-websocket。它同时实现了客户端和服务器,所以应该可以使用这个库来编写代理。
我需要OpenResty的功能(根据Cookie值代理不同的主机)
检查example和this answer,ngx.balancer会做您需要做的事情。
https://stackoverflow.com/questions/67278847
复制相似问题