Sometimes we face issues like we have only one IP accessible from outside due to security concern and we need to access other servers from outside. Like Accessing a remote database securely from your local machine especially when direct access isn’t allowed. However, by using NGINX as a proxy for your database, you can efficiently route SQL Developer traffic through an intermediary server. This setup not only ensures security but also gives you better control over the your network path.
If your target database is hosted on Server2 and you can only reach it through Server1, then using NGINX’s stream module on Server1 is an excellent approach. It lets SQL Developer or any client tool communicate with the database as though it’s running directly on Server1.
Why Use NGINX as a Proxy for Databases?
For environments with restricted access, routing database connections through a NGINX proxy layer provide multiple benefits like:
It enhances security by hiding the real DB host.
It enables access without opening direct ports on the DB server.
It also allows easier logging and connection management
And also, with NGINX’s lightweight performance, this method becomes both efficient and reliable.
Step-by-Step Guide to Configure NGINX as a Proxy
Step1: Install Stream Module and NGINX packages
First, ensure that the NGINX installation supports the stream module. On RHEL-based systems, you can install it using:
dnf install nginx-mod-stream
dnf install nginx
Step2: Now you have to configure the file. Just add your configuration which is mentioned below to end of the nginx.conf after http section:
Below block instructs NGINX to listen on port 1521 and forward all traffic to Server2’s database.
stream {
upstream db_backend {
server server2:1521; # Replace with your actual DB IP or hostname
}
server {
listen 1521;
proxy_pass db_backend;
}
}
Step3: Disable Port Conflicts, While testing your setup, you might see errors like:
bind() to 0.0.0.0:80 failed (98: Address already in use)
This indicates that another service, such as Apache or a previously running NGINX instance, is already using port 80.
To resolve this, You can stop the service if not required or can take appropriate action.
In many enterprise setups, direct access to database servers is restricted for security reasons. Therefore, using NGINX as a proxy for database access is not just a workaround. It’s a best practice in many secure environments.
By combining NGINX’s stream module with proper configuration, you ensure that SQL Developer can interact with remote databases without compromising security or accessibility.