如何配置Nginx通过subdomain.domain.tld:80使ssh服务器可用

xae*_*des 5 subdomain ssh nginx

我想通过端口80上的子域使端口22上的ssh服务器可用。

我认为应该是这样的:

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

    location / {
        proxy_pass          http://localhost:22;
    }
}
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。nginx将接受此配置并从此配置开始,但是我从只能得到空响应ssh.domain.tld:80

我想念什么?

小智 6

由于 Nginx 版本 1.9.0,NGINX 支持 ngx_stream_core_module 模块,它应该通过 --with-stream 启用。当启用流模块时,它们可以通过 ssh 协议 tcp 代理

stream {
upstream ssh {
    server localhost:22;
}
    server {
    listen        80;
    proxy_pass    ssh;
} }
Run Code Online (Sandbox Code Playgroud)

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