【发布时间】:2021-07-20 13:08:48
【问题描述】:
我使用 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()
}
}
}
}
它是生产代理的更简单版本,但与 websockets 返回相同的错误。我尝试将代理与纯 nginx 一起使用,它可以与 websockets 一起使用,但我需要 OpenResty 的功能(基于 cookie 值代理不同的主机)。
上面的文件有没有简单的错误或者OpenResty没有websocket能力?
【问题讨论】:
标签: nginx websocket reverse-proxy openresty