一、nginx编辑模块中需要有stream
执行编译命令:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
二、修改nginx.conf配置文件
stream {
//转发websocket
upstream backend {
server ip地址:端口号; // socket转发的服务
}
server {
listen 端口号;//本机开放的socket端口
proxy_connect_timeout 1s;
proxy_timeout 5s;
proxy_pass backend;
}
//转发sftp
upstream dnc_sftp {
hash $remote_addr consistent;
server sftp_ip:sftp_端口 max_fails=3 fail_timeout=30s;
}
server{
listen 端口号;//本地开放的sftp端口
proxy_connect_timeout 5s;
proxy_timeout 5s;
proxy_pass dnc_sftp;
}
}
以上配置可放在http块上方