Author: aashutosh
Updated: 17 Feb 2023 9:30 p.m.
Summary : Load balance & Reverse proxy multiple applications hosted on different resources using a single NGINX server.
Create a new Nginx configuration file in the /etc/nginx/sites-available
directory, for example jira.conf
, and add the following configuration:
upstream jira {
server 192.168.1.10:8080;
server 192.168.1.11:8080;
server 192.168.1.12:8080;
server 192.168.1.13:8080;
}
server {
listen 80;
server_name jira.example.com;
location / {
proxy_pass http://jira;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
This configuration uses a jira upstream block to define a group of Jira servers, 192.168.1.10:8080, 192.168.1.11:8080, 192.168.1.12:8080, and 192.168.1.13:8080, that Nginx can balance traffic to. The server block tells Nginx to listen on port 80 for requests to jira.example.com, and proxy those requests to the Jira servers.
Create a new Nginx configuration file in the /etc/nginx/sites-available
directory, for example confluence.conf
, and add the following configuration:
upstream confluence {
server 192.168.2.10:8090;
server 192.168.2.11:8090;
server 192.168.2.12:8090;
server 192.168.2.13:8090;
}
server {
listen 80;
server_name confluence.example.com;
location / {
proxy_pass http://confluence;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
This configuration uses a confluence upstream block to define a group of Confluence servers, 192.168.2.10:8090, 192.168.2.11:8090, 192.168.2.12:8090, and 192.168.2.13:8090, that Nginx can balance traffic to. The server block tells Nginx to listen on port 80 for requests to confluence.example.com, and proxy those requests to the Confluence servers.
Create symbolic links in the /etc/nginx/sites-enabled directory to the jira.conf and confluence.conf files:
$ sudo ln -s /etc/nginx/sites-available/jira.conf /etc/nginx/sites-enabled/
$ sudo ln -s /etc/nginx/sites-available/confluence.conf /etc/nginx/sites-enabled/
In this configuration, Nginx will listen on port 80 for incoming requests. When it receives a request for jira.example.com, it will proxy the request to the Jira server cluster defined in the upstream block. Similarly, when it receives a request for confluence.example.com, it will proxy the request to the Confluence server cluster defined in the upstream block.
After making the changes, restart Nginx to apply the changes:
$ sudo service nginx restart