In this post we will learn, how can we use apache and NGINX webserver as a reserve proxy. Means if we are using an application of different port and we want to use that application on port 80 or 443.
For Apache
Step 1: Install apache2 webserver
sudo apt-get update
sudo apt-get install apache2 -y
apache2 -v
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl restart apache2
[Like I have done in previous Jenkins post]
cd /etc/apache2/sites-availbale
sudo vim jenkins.conf
ServerName jenkins.domain
ServerAlias www.jenkins.domain
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://jenkins.host/
Order allow,deny
Allow from all
ProxyPreserveHost on
Save and Exit from the jenkins.conf file.
Step 4: Now, we have to install the following apache module
a2enmod proxy
a2enmod proxy_http
systemctl restart apache2
Step 5: Deactivate the default apache2 configuration file
Let assume we are in /etc/apache2/sites-available. Rename the default 000-default.conf
sudo mv 000-default.conf 000.default.conf.bkp
Remove the default symlink and create symlink for jenkins.conf file
sudo rm 000-default.conf
sudo ln -s ../sites-available/jenkins.conf /etc/apache2/sites-enabled/
sudo systemctl restart apache2
For NGINX
Create a file name jenkins in the following location:
sudo vim /etc/nginx/sites-enabled/jenkins
Copy the following lines inside it
server {
listen 80;
server_name jenkins.cloudshades.in;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
Restart the NGINX service
systemctl restart nginx