The*_*nix 17 ssl ssh nginx proxy http-proxy
我正在尝试使用 nginx 通过 https 连接设置 ssh。我还没有找到任何有效的例子,所以任何帮助将不胜感激!
~$ cat .ssh/config
Host example.net
Hostname example.net
ProtocolKeepAlives 30
DynamicForward 8118
ProxyCommand /usr/bin/proxytunnel -p ssh.example.net:443 -d localhost:22 -E -v -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
~$ ssh user@example.net
Local proxy ssh.example.net resolves to 115.xxx.xxx.xxx
Connected to ssh.example.net:443 (local proxy)
Tunneling to localhost:22 (destination)
Communication with local proxy:
-> CONNECT localhost:22 HTTP/1.0
-> Proxy-Connection: Keep-Alive
-> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win32)
<- <html>
<- <head><title>400 Bad Request</title></head>
<- <body bgcolor="white">
<- <center><h1>400 Bad Request</h1></center>
<- <hr><center>nginx/1.0.5</center>
<- </body>
<- </html>
analyze_HTTP: readline failed: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host
Run Code Online (Sandbox Code Playgroud)
服务器上的 Nginx 配置;
~$ cat /etc/nginx/sites-enabled/ssh
upstream tunnel {
server localhost:22;
}
server {
listen 443;
server_name ssh.example.net;
location / {
proxy_pass http://tunnel;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
ssl on;
ssl_certificate /etc/ssl/certs/server.cer;
ssl_certificate_key /etc/ssl/private/server.key;
}
~$ tail /var/log/nginx/access.log
203.xxx.xxx.xxx - - [08/Feb/2012:15:17:39 +1100] "CONNECT localhost:22 HTTP/1.0" 400 173 "-" "-"
Run Code Online (Sandbox Code Playgroud)
vdb*_*oor 13
Nginx 不支持转发代理请求(HTTP CONNECT 方法),这就是您从 Nginx 收到“错误请求”响应的原因。Proxytunnel 能够连接到 Nginx,但从那里它停止了。AFAIF Nginx 作者没有计划支持转发代理请求,因为他们喜欢专门为 HTTP 服务。Apache 拥有用于其他所有功能的模块,让您可以自由地使用这些奇特的功能。
您可以查看sslh,它可以将端口 443 处的传入流量多路复用到 Nginx(在 127.0.0.1:443 处侦听)、SSH 或 OpenVPN。确保您允许sslh监听公共 IP 地址,而不是打开,0.0.0.0因为它与127.0.0.1:433Nginx 正在监听的位置重叠。
另一种选择是使用 Squid,但我在那里没有经验。
我从未见过这种设置,我怀疑它是否可以工作,因为 nginx 希望能够将传入连接视为 HTTP 并使用 HTTP 与上游通信。为什么要通过nginx进行代理呢?