nginx代理ssh请求

问题: gitea搭建完成后,无法使用ssh访问

原因:
ssh 通过默认端口22, nginx配置的https/http只能通过web访问
需要将 ssh对应的端口也暴露出来

现有所有的服务请求路径 域名解析 -> nginx -> 本地frpc -> 家庭服务器

解决: 通过nginx的stream模块转发ssh请求

  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 09
  • 10
  • 11
  • 12
  • 13
upstream ssh { server localhost:22; } server { listen 322; proxy_connect_timeout 60s; proxy_timeout 60s; proxy_pass ssh; } git remote set-url origin ssh://git@domain:322/user/porject.git 访问请求 git clone ssh://git@domain:322/user/porject.git

其他

  1. nginx 查看配置模块

    nginx -V

    • 01
    • 02
    • 03
    • 04
    • 05
    • 06
    [root@VM-0-7-centos opt]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.20.2 built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-ipv6 --with-http_ssl_module
  2. 安装nginx

    ngx_http_v2_module 模块 (1.9.5) 提供对 HTTP/2 的支持并取代 ngx_http_spdy_module 模块。

    这个模块不是默认构建的,它应该使用 --with-http_v2_module 配置参数启用。

    • 01
    • 02
    • 03
    • 04
    • 05
    • 06
    • 07
    • 08
    • 09
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    wget https://nginx.org/download/nginx-1.22.1.tar.gz tar -zxvf nginx-1.22.1.tar.gz cd nginx ./configure \ --prefix=/usr/local/nginx/ \ --user=nginx \ --group=nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-ipv6 \ --with-stream \ --with-stream_ssl_module \ --with-http_v2_module make cp /opt/nginx-1.22.1/objs/nginx /usr/sbin/nginx nginx