nginx 反向代理Mysql 3306端口

位置:首页>文章>详情   分类: 教程分享 > nginx教程   阅读(2438)   2023-03-28 11:29:14
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;
    }
}




 
标签:
地址:https://www.leftso.com/article/951.html

相关阅读

nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议nginx.conf配置如下:user nginx; worker_processe...
前置说明,项目配置了个全局PATH,估计是为了方便复杂环境单容器多项目部署用的老项目配置方式var PATH = [[${#httpServletRequest.getScheme() + ":...
nginx代理Tomcat带路径的项目location / {                 proxy_pass http://localhost:8080/v1/;            ...
nginx日志默认格式如下:$remote_addr-$remote_user[$time_local]"$request"$status$body_bytes_sent"$http_refer...
Linux(centos) nginx安装和nginx入门配置方法1.切换至root用户$su - 2.执行在线安装命令#yum install nginx -y 如果上面提示以下内容[root...
centos 6 nginx+php7环境配置 做一记录,谨防采矿 $title(php.conf) # # The default server # server { listen ...
打开任务管理器发现一大堆nginx进程
最近网站被恶意访问了,了解了一些基础防护手段,nginx屏蔽ua访问 编写文件agent_deany.conf #使用方法 #创建目录 /etc/nginx/conf.d/deny [注意]...
1.root的用法location /request_path/image/ { root /local_path/image/; } 这样配置的结果就是当客户端请求 /reques...
最近博客升级总是nginx原生的502页面,感觉有些不友好,特此研究了下502页面的配置nginx 502配置502页面核心配置 #502 page error_p...