nginx 反向代理Mysql 3306端口

编程教程 > nginx (3849) 2024-11-26 14:39:04

nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议

nginx.conf配置如下:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

# 重点配置
stream {

    upstream cloudsocket {
       hash $remote_addr consistent;
      # $binary_remote_addr;
       server 116.115.119.7:33306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 33306;#数据库服务器监听端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass cloudsocket;
    }
}

# 重点配置
stream {

    upstream cloudsocket {
       hash $remote_addr consistent;
      # $binary_remote_addr;
       server 116.115.119.7:33306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 33306;#数据库服务器监听端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass cloudsocket;
    }
}

 

 


 

 

 


评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议nginx.conf配置如下:user nginx; worker_process...
前置说明,项目配置了个全局PATH,估计是为了方便复杂环境单容器多项目部署用的老项目配置方式var PATH = [[${#httpServletRequest.getScheme() + ":...
PVE配置nginx代理访问。nginx配置:server { listen 10101 ssl; server_name pve.ok.top; #ssl on; #从腾...
nginx代理Tomcat带路径的项目location / {                 proxy_pass http://localhost:8080/v1/;          ...
引言    modbus tcp通讯Java的方案之前已经讲解过一种,modbus4j实现Java语言的modbus tcp协议通讯
Windows系统查看端口占用
Linux(centos) nginx安装和nginx入门配置方法1.切换至root用户$su - 2.执行在线安装命令#yum install nginx -y 如果上面提示以下内容[root...
Nginx 安装Nginx 安装参考:Linux yum nginx安装和nginx入门配置方法-XQLEE'BlogAlpine Linux nginx安装配
最终看起来像这样 nginx (host,ssl) -&gtl; harbor-nginx (non-ssl) -&gtl; harbor。说明首先服务上安装有 nginx,且
Nginx 配置日志nginx默认的日志配置在nginx.conf配置文件。
alpineLinux安装nginx更新软件apkupdate安装nginxapkaddnginx查看nginx版本nginx-vnginx启停启动停止servicenginxstop重启ser...
打开任务管理器发现一大堆nginx进程
内置变量$args #请求中的参数值$query_string #同 $args$arg_NAME #GET请求中NAME的值$is_args #如果请求中有参
需求将静态资源如css/js/图片缓存到不用每次都到后端服务去拿取,减少性能消耗。 配置nginx缓存配置缓存文件存放信息在nginx配置文件,httpd内部配
最近网站被恶意访问了,了解了一些基础防护手段,nginx屏蔽ua访问 编写文件agent_deany.conf #使用方法 #创建目录 /etc/nginx/conf.d/deny...