原文链接:https://blog.csdn.net/Activity_Time/article/details/95767390
1. stream模块安装
nginx默认安装的时候无法加载流stream模块,需要在启动参数里加上–with-stream。
解决方法:
重新对源文件进行编译、安装,通过添加–with-stream参数指定安装stream模块。
nginx安装教程
[root@localhost nginx-1.12.2]# ./configure --with-stream
[root@localhost nginx-1.12.2]# make & make install
configure
命令设定安装参数
# 常用模块配置
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-stream \
--with-http_ssl_module
2.配置文件 nginx.conf
stream模块位于与http模块相同的层次
示例:
stream {
upstream backend {
server 202.118.163.18:3306;
}
upstream landm {
server 202.118.163.18:8092;
}
upstream nginxCon {
server 202.118.166.247:22;
}
upstream stu.neau.actim.top {
server 202.118.163.18:80;
server 202.118.167.86:9004;
server 202.118.167.86:9003;
server 202.118.167.86:9002;
server 202.118.167.86:9001;
}
server {
listen 8088;
proxy_connect_timeout 8s;
proxy_timeout 24h; #¿¿¿¿
proxy_pass backend;
}
server {
listen 8082;
proxy_connect_timeout 8s;
proxy_timeout 24h; #¿¿¿¿
proxy_pass landm;
}
server {
listen 8686;
proxy_connect_timeout 8s;
proxy_timeout 24h; #¿¿¿¿
proxy_pass nginxCon;
}
server {
listen 8093;
proxy_connect_timeout 8s;
proxy_timeout 24h; #¿¿¿¿
proxy_pass stu.neau.actim.top;
}
}
3. 代理mysql、文件下载等tcp连接
stream在使用上与http相近,只需配置upstream然后再配置server即可,参考上面的配置,
代理mysql只需用反向代理服务器的一个端口去代理数据库服务器(集群)的端口即可,文件下载亦然
参考文章:
Nginx1.14.2新增tcp/udp代理stream(详细)
ssl模块安装(https)
Nginx反向代理+负载均衡简单实现(https方式)
https://blog.csdn.net/Activity_Time/article/details/95770900