Nginx 代理 MySQL 端口
配置
在nginx.html
添加如下配置
stream {
include /etc/nginx/conf.d/*.stream;
}
在conf.d
中添加mysql.stream
,如下:
upstream MYSQL {
server <mysql-ip>:<mysql-port>;
}
server {
listen 3306;
proxy_connect_timeout 30s;
proxy_timeout 600s;
proxy_pass MYSQL;
}
FAQ
nginx: [emerg] unknown directive "stream" in /usr/share/nginx/modules/nginx-mysql.conf:2
解决方式:在nginx.conf第一行添加load_module /usr/lib/nginx/modules/ngx_stream_module.so;