Nginx配置TCP请求转发
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请求转发的更多相关文章
- 在nginx配置将请求转发到某个真实后端服务ip
一.打开nginx机器的nginx配置文件 命令: locate nginx.conf 会列出所有nginx.conf文件的地址, 一般咱们要用的nginx配置文件是/usr/local/nginx/ ...
- Nginx配置以及域名转发
工程中的nginx配置 #user nobody; worker_processes 24; error_log /home/xxx/opt/nginx/logs/error.log; pid /ho ...
- Nginx 配置TCP代理
Nginx 1.9 版本以后增加了stream模块,可以对tcp,udp请求进行代理和负载均衡了,今天来体验一下首先编译安装过程configure的时候增加选项 --with-stream --wit ...
- nginx代理tcp请求
1.概述 ngx_stream_core_module 这个module在nginx1.90后开始支持.开启nginx的tcp代理支持--with-stream=dynamic --with-stre ...
- nginx 配置 https 请求
1,先去这个网站申请一下证书 https://certmall.trustauth.cn/Home/Member/index/id/1521167511.html 上面会教你怎么去做. 2,就是配置自 ...
- Nginx配置图片请求
Nginx的下载安装这里就不赘述了, 在Nginx的配置文件nginx.conf 或者 自定义的配置文件中加入如下配置. server { listen 80; server_ ...
- nginx配置打印请求响应内容
#放在http{}里面 log_format kyh ' [$time_local] "$request" $status \n' 'req_header:"$req_h ...
- nginx 配置路由规则转发配置记录
工作中公司要求针对经销商PC端和工厂PC端的访问地址固定访问. 经销商PC端 http://localhost/ 工厂PC端 http://localhost/fac 文件磁盘路径: /crm/n ...
- Nginx 配置https请求
通过阿里云生成指定的https证书文件xxxx.key 和 xxxx.pem文件 在阿里云上申请的https证书的是pem格式,转成cer 先在终端cd到文件目录下 然后 openssl x509 - ...
随机推荐
- P1456 Monkey King
题目地址:P1456 Monkey King 一道挺模板的左偏树题 不会左偏树?看论文打模板,完了之后再回来吧 然后你发现看完论文打完模板之后就可以A掉这道题不用回来了 细节见代码 #include ...
- SpringCloud Zuul(路由网关)
⒈Zuul是什么? Zuul包含了两个最主要的功能,对请求的路由和过滤.其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础.过滤器功能则负责对请求的处理过程进行干预,是实 ...
- Elasticsearch 5.4.3实战--环境搭建
1. 选择搭建的服务器信息 $ uname -a Linux SA0124 2.6.32-642.11.1.el6.x86_64 #1 SMP Fri Nov 18 19:25:05 UTC 2016 ...
- sorter函数参数设置
python内置sorted函数排完序生成一个新列表,而列表list.sorted则是直接在原列表上修改 sorted默认排序是正序,即从小到大. 若想倒着排序,则reverse=True 当需要排序 ...
- 集合排序 Comparator和Comparable的使用区别
Java 排序 Compare Comparator接口 Comparable接口 区别 在Java中使用集合来存储数据时非常常见的,集合排序功能也是常用功能之一.下面看一下如何进行集合排序,常用的 ...
- Mysqli扩展类
Mysqli 扩展是需要php5.0版本以上的支持 主要有以下的3个类 MySQLi类,基本操作 MySQL_STMT类,预处理操作 MySQLi_RESULT类,结果操作 Mysqli的编写有两种方 ...
- Python3学习笔记02-基础语法
默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串 ' # -*- coding:cp-1252 -*-' 也可以指定其他编码,以上用cp-1252字符 ...
- Mudo C++网络库第十一章学习笔记
反思C++面向对象与虚函数 C++语言学习可以看<C++ Primer>这本书; 在C++中进行面向对象编程会遇到其他语言中不存在的问题, 其本质原因是C++ class是值语义, 而非对 ...
- ffmpeg 版本升级到 4.0 增加 libaom 库 [AOMedia 的 AV1 视频编码格式]
win10 中交叉编译 libaom 时 注意事项 libaom 源代码 下载 git -c "http.proxy=ip:port" clone https://aomedia. ...
- css3时钟
参考资料: 奇舞团: http://www.75team.com/archives/851 DEMO:demo 截图: 代码: <!DOCTYPE html> <html lang= ...