ssh(sftp)使用stream分流且通过proxy_protocol设置了真实IP后,由于修改了请求头,可能会导致无法访问,出现如下错误:
ssh: handshake failed: ssh: invalid packet length, packet too large
解决方法很简单,在nginx中再配置一个server监听
stream {
upstream ssh {
server 127.0.0.1:222;
}
upstream web {
server tls.example.com:443;
}
map $ssl_preread_protocol $upstream {
"" ssh;
default web;
}
# SSH and SSL on the same port
server {
listen 443;
listen [::]:443;
proxy_pass $upstream;
ssl_preread on;
proxy_protocol on;
}
#add
server {
listen 222 proxy_protocol;
listen [::]:222 proxy_protocol;
proxy_pass ssh.example.com:22;
ssl_preread off;
proxy_protocol off;
}
}
参考内容:
评论区