Nginx配置TCP请求转发

1.TCP请求转发基于stream在1.9版本前,需要单独编译安装该组建:

# 依赖服务
[root@baolin conf]#yum -y install pcre-devel openssl openssl-devel library # 用户
[root@baolin conf]#useradd nginx -u 1000 # 编译安装 stream 组建
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module

2.配置nginx.conf 实现TCP得请求转发

[root@baolin conf]# cat /usr/local/nginx/nginx.conf
worker_processes 1; events {
worker_connections 1024;
} # 此为TCP转发请求 stream
stream {
# 后端指向 server 的 8085 端口 stream_backend 组
upstream stream_backend {
server 10.50.2.11:8085;
server 10.50.2.19:8085;
} # 后端指向 server 的 8090 端口 cns组
upstream cns {
server 10.50.2.11:8090;
server 10.50.2.19:8090;
}
server {
listen 443 ssl;
proxy_pass stream_backend;
# 指定key 和 crt 地址
ssl_certificate /etc/ssl/certs/my.crt;
ssl_certificate_key /etc/ssl/certs/my.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 4h;
ssl_handshake_timeout 30s;
}
server {
# 本机监听端口 8080
listen 8080; # 请求抛给 stream_backend 组
proxy_pass stream_backend;
}
server {
# 本机监听端口 8090
listen 8090; # 请求抛给 cns 组
proxy_pass cns;
}
} # 此为HTTP 转发请求 http
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
gzip_comp_level 9;
gzip_types text/css text/xml application/javascript;
gzip_vary on; include /etc/nginx/mime.types;
default_type application/octet-stream; # 后端指向 server 的 8585 端口 cns_node 组
upstream cns_node {
server 10.50.2.51:8585 weight=3;
server 10.50.2.59:8585 weight=3;
} server {
listen 8585;
server_name umout.com; access_log /etc/nginx/logs/server02_access.log main; location /{
index index.html index.htm index.jsp;
proxy_pass http://cns_node1;
include /etc/nginx/proxy.conf;
}
}
}

Nginx配置TCP请求转发的更多相关文章

  1. 在nginx配置将请求转发到某个真实后端服务ip

    一.打开nginx机器的nginx配置文件 命令: locate nginx.conf 会列出所有nginx.conf文件的地址, 一般咱们要用的nginx配置文件是/usr/local/nginx/ ...

  2. Nginx配置以及域名转发

    工程中的nginx配置 #user nobody; worker_processes 24; error_log /home/xxx/opt/nginx/logs/error.log; pid /ho ...

  3. Nginx 配置TCP代理

    Nginx 1.9 版本以后增加了stream模块,可以对tcp,udp请求进行代理和负载均衡了,今天来体验一下首先编译安装过程configure的时候增加选项 --with-stream --wit ...

  4. nginx代理tcp请求

    1.概述 ngx_stream_core_module 这个module在nginx1.90后开始支持.开启nginx的tcp代理支持--with-stream=dynamic --with-stre ...

  5. nginx 配置 https 请求

    1,先去这个网站申请一下证书 https://certmall.trustauth.cn/Home/Member/index/id/1521167511.html 上面会教你怎么去做. 2,就是配置自 ...

  6. Nginx配置图片请求

    Nginx的下载安装这里就不赘述了, 在Nginx的配置文件nginx.conf 或者 自定义的配置文件中加入如下配置. server {       listen 80;       server_ ...

  7. nginx配置打印请求响应内容

    #放在http{}里面 log_format kyh ' [$time_local] "$request" $status \n' 'req_header:"$req_h ...

  8. nginx 配置路由规则转发配置记录

    工作中公司要求针对经销商PC端和工厂PC端的访问地址固定访问. 经销商PC端 http://localhost/ 工厂PC端   http://localhost/fac 文件磁盘路径: /crm/n ...

  9. Nginx 配置https请求

    通过阿里云生成指定的https证书文件xxxx.key 和 xxxx.pem文件 在阿里云上申请的https证书的是pem格式,转成cer 先在终端cd到文件目录下 然后 openssl x509 - ...

随机推荐

  1. [sklearn] 官方例程-Imputing missing values before building an estimator 随机填充缺失值

    官方链接:http://scikit-learn.org/dev/auto_examples/plot_missing_values.html#sphx-glr-auto-examples-plot- ...

  2. RabbitMQ与SpringBoot整合

    RabbitMQ  SpringBoot  一.RabbitMQ的介绍 二.Direct模式 三.Topic转发模式 四.Fanout Exchange形式 原文地址: https://www.cnb ...

  3. 【转】python操作excel表格(xlrd/xlwt)

    [转]python操作excel表格(xlrd/xlwt) 最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异, ...

  4. ROI Pool和ROI Align

    这里说一下ROI Pool和ROI Align的区别: 一.ROI Pool层: 参考faster rcnn中的ROI Pool层,功能是将不同size的ROI区域映射到固定大小的feature ma ...

  5. python中的正则表达式--re模块

    参考博客:https://www.cnblogs.com/tina-python/p/5508402.html 这里说一下python的re模块即正则表达式模块,先列出其中涉及到的各种字符和模式等: ...

  6. Node.js的模块系统

    编写稍大一点的程序时一般都会将代码模块化.Node.js提供了一个简单的模块系统.模块既可能是一个文件,也可能是包含一个或多个文件的目录. 模块的创建  如果模块是个文件,一般将代码合理拆分到不同的J ...

  7. Python运维开发基础09-函数基础【转】

    上节作业回顾 #!/usr/bin/env python3 # -*- coding:utf-8 -*- # author:Mr.chen # 实现简单的shell命令sed的替换功能 import ...

  8. VS2017中VC++项目添加StringTable资源

    1.在资源视图中选择Resource.rc,右键弹出菜单,选择[添加资源] 2.在[添加菜单]对话框中选择[String Table],新建即可

  9. OpenSIPS 1.11.1安装记录

    说明:操作系统Centos 6.5  64位 安装步骤: 1.安装依赖包 : yum -y install gcc make gdb wget yum -y install flex bison nc ...

  10. PHPExcel导出数据时字段超过26列出错Invalid cell coordinate [1

    http://blog.csdn.net/dl425134845/article/details/46650961 以下是解决方案函数 /** *   方法名:    getExcel *   作用  ...