1. Scene
Mysql database in the pure Intranet environment, no public IP, no VPN.
2. Programme
Install nginx on a server with public IP and in the same Intranet environment with MySQL service to realize the routing and forwarding of MySQL access.
3. Nginx installation
Nginx version needs 1.9 or above. Nginx not only implements HTTP reverse proxy, but also supports TCP reverse proxy.
1) When compiling nginx, you need to add the parameter — with stream to load NGX_ stream_ core_ Module
Examples
./configure –prefix=/opt/software/nginx –with-http_ stub_ status_ module –with-http_ ssl_ module –with-stream –with-stream_ ssl_ module –with-pcre=/usr/local/src/pcre-8.35
4. Nginx configuration file nginx.conf
Monitor port 3307 with public IP server, and jump to port 3306 of 172.31.88.27.
Special note: stream should be in the same level directory as HTTP
stream {
upstream mysql3306 {
hash $remote_addr consistent;
server 172.31.88.27:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 3307;
proxy_connect_timeout 10s;
proxy_timeout 200s;
proxy_pass mysql3306;
}
}
Read More:
- NxL job cluster nginx routing forwarding and reverse proxy
- Nginx reverse proxy report 400 error solution!
- Nginx front end and back end separation + service cluster reverse proxy
- nginx: [emerg] unknown directive “proxy_pass“
- Nginx startup error: nginx: [error] open() “/ var / run / nginx/ nginx.pid The solution of “failed (2: no such file or directory)”
- Nginx proxy appears Failed to load resource: net::ERR_NAME_NOT_RESOLVED
- nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
- nginx: [error] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
- Proxy error:could not proxy request
- Nginx error: nginx: [error] invalid PID number “” in “/run/nginx.pid”
- Google set proxy, ERR_PROXY_CONNECTION_FAILED
- Exception in thread “main“ java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to XXX
- /var/run/nginx/nginx.pid” failed (2: No such file or directory)
- nginx: [error] invalid PID number ““ in “/data/nginx/logs/nginx.pid“
- nginx: [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
- Solve the problem of starting nginx nginx.pid error
- When configuring the proxy with Vue, the front-end requests the server-side error 504; the Vue console reports the error occurred while trying to proxy request
- nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
- nginx: open() “/var/run/nginx.pid“ failed (2: No such file or directory)
- Nginx start error: job for nginx.service failed because the control process exited with error code