Nginx 代理mysql

Posted 衣舞晨风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 代理mysql相关的知识,希望对你有一定的参考价值。

docker-compose.yml

version: '2.0'

services:
  nginx:
    restart: always
    image: nginx:1.13.9-alpine
    ports:
      - 63306:63306
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf

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 

    log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
   
    access_log  /var/log/nginx/access.log  proxy; 
       
    upstream mysql_server 
        server 127.0.0.1:3306;
    

    server 
        listen 63306;
        proxy_pass mysql_server;
    

以上是关于Nginx 代理mysql的主要内容,如果未能解决你的问题,请参考以下文章

Nginx 代理mysql

Nginx 代理mysql

Nginx 代理MySQL

Nginx 代理MySQL

Nginx 代理MySQL

Nginx代理tcp协议(mysql)