# 原文链接
~~~~0031400 blog - nginx代理mysql连接
### nginx配置
```
stream {
upstream mysql_backend {
server mysql_backend_address:3306;
}
server {
listen 52080;
proxy_pass mysql_backend;
}
}
```
### 示例
#### serv00 freebsd nginx 代理 mysql 实现数据库远程连接
创建目录,安装 nginx 编译后的文件 ~~~~nginx-1.27.4-freebsd-amd64.zip
~~bash</s><i> </i>mkdir ~/nginx cd ~/nginx wget https://file.0031400.xyz/nginx-1.27.4-freebsd-amd64.zip unzip nginx-1.27.4-freebsd-amd64.zip rm nginx-1.27.4-freebsd-amd64.zip<i> </i><e>
修改配置文件
worker_processes 5;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log logs/access.log;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_max_temp_file_size 0;
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
client_body_temp_path tmp/client_body;
proxy_temp_path tmp/proxy;
fastcgi_temp_path tmp/fastcgi;
uwsgi_temp_path tmp/uwsgi;
scgi_temp_path tmp/scgi;
include conf/http.d/*.conf;
}
stream {
upstream mysql_backend {
server mysql14.serv00.com:3306;
}
server {
listen 端口;
proxy_pass mysql_backend;
}
}
<e>```</e></CODE>
<p>准备操作</p>
<CODE><s>```
mkdir ~/nginx/tmp
<e>```</e></CODE>
<p>启动</p>
<CODE><s>```
~/nginx/sbin/nginx -p ~/nginx
<e>```</e>
~~####~~ 注意事项
<LIST>
- ~~-~~ serv00有进程限制,不能超过20个,nginx的<C>~~`</s>worker_processes<e>`</e></C>最好限制少一点
- -~~ <C>~~`</s>ps aux | grep nginx<e>`</e></C>看nginx进程
- -~~ <C>~~`</s>pkill nginx<e>`</e></C>停止nginx
- -~~ 如果进程满了,连<C>`</s>ps<e>`</e></C> <C>`</s>pkill<e>`</e></C>都运行不了,使用<C>`</s>kill -9 -1<e>`</e></C>删除所有进程</LIST></r>
0
2

2 条回复
排序