Skip to content

Instantly share code, notes, and snippets.

@philipz
Created July 3, 2015 07:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philipz/fadd2ddb92c4cf07fb10 to your computer and use it in GitHub Desktop.
Save philipz/fadd2ddb92c4cf07fb10 to your computer and use it in GitHub Desktop.
Nginx TCP Load balancing for Mysql(3306)

TCP LOAD BALANCING

user  nginx;
worker_processes  1;

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


events {
    worker_connections  1024;
}

stream {
        upstream stream_backend {
            least_conn;
            server 172.17.0.34:3306 max_fails=2 fail_timeout=30s;
            #server backend2.example.com:12345 max_fails=2 fail_timeout=30s;
            #server backend3.example.com:12346 max_conns=3;
        }

        server {
            listen 3306;
            proxy_connect_timeout 1s;
            proxy_timeout 3s;
            proxy_pass stream_backend;
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment