proxytunnel 및 nginx를 사용하는 SSH를 통한 SSH -v -H “User-Agent: Mozilla/4.0

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

서버의 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 "-" "-"



답변

Nginx는 정방향 프록시 요청 (HTTP CONNECT 메소드)을 지원하지 않으므로 Nginx에서 “잘못된 요청”응답을받습니다. Proxytunnel은 Nginx에 연결할 수 있지만 거기서 중지됩니다. AFAIF Nginx 작성자는 HTTP를 실제로 제공하는 것을 전문으로하기 때문에 정방향 프록시 요청을 지원할 계획이 없습니다. Apache에는 다른 모든 기능을위한 모듈이있어 이국적인 기능을 자유롭게 사용할 수 있습니다.

포트 443에서 들어오는 트래픽을 Nginx (127.0.0.1:443에서 청취), SSH 또는 OpenVPN으로 다중화 할 수 있는 sslh 를 볼 수 있습니다 . Nginx가 수신 하는 위치 와 겹치지 sslh않도록 퍼블릭 IP 주소를 듣지 않도록하십시오 .0.0.0.0127.0.0.1:433

또 다른 옵션은 오징어를 사용하는 것이지만 경험이 없습니다.


답변

나는 이런 종류의 설정을 본 적이 없으며 nginx가 들어오는 연결을 HTTP로 취급하고 HTTP를 사용하여 업스트림과 통신 할 수 있기를 기대하기 때문에 작동하지 않을 것이라고 의심합니다. 왜 nginx를 통해 프록시하고 싶습니까?


답변

이것은 오래된 질문이지만 여전히 실제입니다 🙂

다른 사람들이 언급 했듯이이 설정은 Nginx에서 사용할 수있는 HTTP CONNECT 방법이 없기 때문에 거의 사용할 수 없습니다.

참고 : Apache 웹 서버는이 설정을 지원합니다.

그러나 Nginx에는 sslh가없는 솔루션이 있습니다 .HTTP CONNECT를 구현하는 사용자 정의 Nginx 모듈의 형태로 생각합니다.
https://github.com/chobits/ngx_http_proxy_connect_module

이것을 사용하면 ssh 설정에서만 ProxyCommand를 올바르게 사용할 수 있어야합니다.


답변