这里主要记录一下nginx的负载代理stream模块,首先编译的时候需要加上--with-stream, 就像这样

然后nginx.conf里面的配置是在http选项上面加上

#Mysql ReverseProxy
stream {
include mysql.conf;
}

这就是引导读取一个mysql.conf的文件, 然后把反向代理的配置扔进去就行。

mysql.conf

server {
listen 3306;
proxy_connect_timeout 10s;
proxy_timeout 525600m;
proxy_pass 192.168.13.19:3306;
}

然后启动nginx,就这么简单。

还有一个问题就是关于nginx_tcp_proxy_module模块的, nginx1.10以上的版本不支持nginx_tcp_proxy_module了, 所以只能用stream。有关nginx_tcp_proxy_module的配置请转百度。

下面配上我的nginx.conf

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} #Mysql ReverseProxy
stream {
include mysql.conf;
} http {
include mime.types;
default_type application/octet-stream;
include mobile-proxy.conf;
#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 logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
}

nginx的stream反向代理mysql配置的更多相关文章

  1. nginx启用TCP反向代理日志配置

    Nginx使用TCP反向代理日志配置不同于http 修改nginx配置文档/usr/local/nginx/conf/nginx.conf 设置日志格式 stream { log_format pro ...

  2. 【转】Nginx服务器的反向代理proxy_pass配置方法讲解

    [转]Nginx服务器的反向代理proxy_pass配置方法讲解 转自:http://www.jb51.net/article/78746.htm 就普通的反向代理来讲Nginx的配置还是比较简单的, ...

  3. Nginx服务器的反向代理proxy_pass配置方法讲解

    Nginx的配置还是比较简单的,如:   1 2 3 4 location ~ /* { proxy_pass http://127.0.0.1:8008; } 或者可以   1 2 3 4 loca ...

  4. Nginx专题(1):Nginx之反向代理及配置

    摘要:本文从Nginx的概念出发,分别从反向代理的概念.优势.配置代码3个方面介绍了Nginx的特性之一反向代理. 文章来源:宜信技术学院 & 宜信支付结算团队技术分享第一期-宜信支付结算八方 ...

  5. Nginx反向代理的配置

    Chapter: Nginx基本操作释疑 1. Nginx的端口修改问题 2. Nginx 301重定向的配置 3. Windows下配置Nginx使之支持PHP 4. Linux下配置Nginx使之 ...

  6. nginx反向代理的配置优化

    作者:守住每一天 blog:liuyu.blog.51cto.combbs:bbs.linuxtone.orgmsn:liuyubj520#hotmail.comemail:liuyu105#gmai ...

  7. 五、Nginx多Server反向代理配置

    Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了. server_name的匹配顺序 Nginx中的s ...

  8. Nginx实战之反向代理WebSocket的配置实例

    http://www.jb51.net/article/112183.htm 最近在工作中遇到一个需求,需要使用 nginx 反向代理websocket,经过查找一番资料,目前已经测试通过,所以这篇文 ...

  9. Nginx 如何设置反向代理 多服务器,配置区分开来,单独文件保存单个服务器 server 主机名配置,通过 include 实现

    samcao 关注 2015.06.15 10:08* 字数 0 阅读 408评论 0喜欢 0   网络结构如上图.可能你只有一个公网的Ip地址. 但是您的内网有个网站需要映射至外网.而又不想添加其它 ...

随机推荐

  1. idc指令相关

    #按不同数据类型打印当前地址opcode print Byte(ea) print Word(ea) print Dword(ea)

  2. Selenium基础知识(十)截屏

    自动化测试过程中,经常会用截图的方式,更直观的显示展示错误信息:selenium截图的三种方式: driver.get_screenshot_as_file(r'd:\selenium.png') # ...

  3. RNN的深入理解

    针对有着前后序列关系的数据,比如说随着时间变化的数据,显然使用rnn的效果会更好. 循环神经网络的简单结构如下图:简单表示是左边这幅图,展开来看就是右边对每个时刻的数据的处理.单层的RNN网络只有一个 ...

  4. node.js连接本地数据库及json返回数据

    新建一个文件夹node.js,目录下打开命令初始化一下 cnpm init 然后下载express框架 cnpm install express --save 接着下载数据库的依赖 cnpm inst ...

  5. HDU 2256 Problem of Precision(矩阵)

    Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...

  6. 简易C# socket

    服务器 using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Thread ...

  7. ssh简单入门级案例教程

    准备工作:struts2.3.34+spring4.2.2+hibernate3.3.2 导入需要的开发包: struts开发包---注意:javassist-3.18.1-GA.jar包与hiber ...

  8. 混合型log,info按大小分,error按日期

    1.配置文件 <?xml version="1.0" encoding="utf-8"?> <configuration> <!- ...

  9. 说说html 的<!DOCTYPE>声明&标准模式与兼容模式

    我们都知道<!DOCTYPE>声明位于文档的最前面,处于<html>标签之前. <!DOCTYPE>声明不是html标签,它的作用:告知web浏览界面应该使用哪个h ...

  10. Vue系列之 => 钩子函数生命周期

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...