网站开发过程中遇到的问题,优化服务公司,黄村网站建设公司,app安装下载1. 背景
后端服务需要通过部署在跳板机上的 nginx 访问一个外网的 SFTP 服务器。
2. 方法
nginx从 1.9.0 开始#xff0c;新增加了一个stream模块#xff0c;用来实现四层协议的转发、代理或者负载均衡等。
首先检查 nginx 版本信息及是否安装了 stream 模块。
进入 ngi…1. 背景
后端服务需要通过部署在跳板机上的 nginx 访问一个外网的 SFTP 服务器。
2. 方法
nginx从 1.9.0 开始新增加了一个stream模块用来实现四层协议的转发、代理或者负载均衡等。
首先检查 nginx 版本信息及是否安装了 stream 模块。
进入 nginx sbin 目录执行命令
./nginx -V重新安装 nginx在 configure 时加上 --with-stream
./configure --prefix/home/XX/nginx2sftp --with-http_ssl_module --with-stream安装完成后可以将先前的 nginx.conf 复制过来。启动新 nginx 后在检查 nginx 版本信息 然后修改 nginx.conf
stream {upstream sftp{ #自定义命名hash $remote_addr consistent;server sftp服务器的ip:sftp服务器的端口 max_fails3 fail_timeout60s;} server {listen 11002;#本地的监听端口proxy_connect_timeout 300s;proxy_timeout 300s;proxy_pass sftp;}
}将上面的文字放在 http 模块上面然后重启 nginx。
例如代码访问时只需将外网的 SFTP 服务器的IP和端口换成 nginx 的 IP 和监听端口即可。