During project development and deployment, MySQL or Oracle databases are often installed on the intranet, but our application services can only be deployed on the external network. What if the external network service accesses the database connected to the internal network? This time, we will introduce how to access the intranet database from the external network through Nginx configuration.
1. Front-end server
First of all, it is necessary to ensure that there is a front-end processor server that can not only access the internal network database, but also access the front-end processor through the external network. Then install and deploy ngxin on this front-end server to implement data proxy.
2. ngxin configuration
The installation and deployment of ngxin is omitted here, and those who are interested can solve it on Baidu. Here we mainly introduce how to configure the data flow agent. The nginx.conf configuration content is as follows:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
stream {
upstream oracle {
server 192.168.0.1:1521; #原oracle地址
}
upstream mysql {
server 192.168.1.102:3306;
}
server {
listen 3335;# 反向代理后监听的端口,nginx启动后访问192.168.21.100:3335就可以访问到oracleA
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass oracle;
}
server {
listen 8888;# 反向代理后监听的端口
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass mysql;
}
}
Restart nginx after modifying the configuration, and then access the front-end processor through the external network IP and port, which is equivalent to directly accessing the internal network database.
3. Test verification
It can be tested through database client connection tools such as Navicat. The example in the figure below is to access the database at port 3306 through port 8888.