How to configure nginx to make ssh server via subdomain.domain.tld:80 available

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 17:26:03

问题


I want to make the ssh server on port 22 available through a subdomain on port 80.

I thought it should by something like this:

server {
    listen          ssh.domain.tld:80;
    server_name     ssh.domain.tld;

    location / {
        proxy_pass          http://localhost:22;
    }
}

But it won't work. nginx will accept this and start with this configuration, but I only get empty responses from ssh.domain.tld:80.

What am I missing?


回答1:


Since Nginx Version 1.9.0,NGINX support ngx_stream_core_module module, it should be enabled with the --with-stream. When stream module is enable they are possible to ssh protocol tcp proxy

stream {
upstream ssh {
    server localhost:22;
}
    server {
    listen        80;
    proxy_pass    ssh;
} }

https://www.nginx.com/resources/admin-guide/tcp-load-balancing/




回答2:


You should use sslh.

Configure nginx to run on a different port than 80, say 800, and then configure sslh to redirect web traffic to that port in /etc/default/sslh.conf file.

This setup may take 15 min. or less.




回答3:


basically you're looking in the wrong place:

  • stock nginx can proxy web and/or email traffic, it doesn't handle ssh traffic at all
  • the subdomain is a dns isue: configure it in your dns settings, you need an A and/or AAAA record linking ssh.domain.tld to your ssh server's ip-adres
  • the port your ssh server listens on is a ssh server setting (see man sshd_config specifically the ListenAddress and Port directives)


来源:https://stackoverflow.com/questions/14696460/how-to-configure-nginx-to-make-ssh-server-via-subdomain-domain-tld80-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!