Reverse Proxy with Web-servers
Reverse Proxy with Web-servers
A reverse proxy server is a type of proxy serve that typically sits behind the firewall in a private network and directs client requests to the appropriate backed serve. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between client and servers.
We have quite few ways to reverse proxy a particular site or ip address. One among them is by using web servers(Apache httpd & Nginx).
Using Nginx Server
Nginx is an open soure, high performance HTTP server, load balance and reveres proxy software. It has a straightfoward configuration language making it easy to configure.
- Install Nginx on your machine
yum install -y nginx
Ubuntu: apt-get install -y epel-release
apt-get install -y nginx
Debian: apt install -y epel-release
apt install -y nginx
- Start & check the status of service
service nginx start
service nginx status - Check the port number on which Nginx is running
By default, web servers like Nginx & Apache httpd runs on the default 80 port. If you've already started Apache httpd on your machine, you have to stop it first in-order to start the Nginx server.
The alternative would be by changing the port numbers. It's recommend and a best practice if you're running on default port 80 if you're running only specific web-server at a time.
netstat -tnlp
netstat -tnlp ' grep 80
You can run the server running on your machine by providing the url: localhost:80 or just localhost. - Change the configuration in Nginx
Go to /etc/nginx/nginx.conf search for /location {} and append with below configuration.
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Save the changes and exit.
- Restart the server
Allow traffic on you port 80 on your firewall. Finally, visit the following address from your web browser.
localhost:80 or just localhost
Now, you'd be able to see the Jenkins page opening instead of Nginx home page. If you're still seeing Ngnix page, please make the below changes and restart the service again.
/usr/sbin/setsebool httpd_can_network_connect true
localhost:80 or just localhost
Now, you'd be able to see the Jenkins page opening instead of Nginx home page. If you're still seeing Ngnix page, please make the below changes and restart the service again.
/usr/sbin/setsebool httpd_can_network_connect true
By running the local host, you'd be able to see the Jenkins Server.
Using Apache HTTP Server
Apache web server is an open source web server creation, deployment and managed software. Initially developed by a group of software programmers, it is now maintained by the Apache Software Foundation.
- Install Apache http on your machine
Ubuntu : apt-get install -y httpd
Debian: apt install -y httpd
- Start & check the status of service
service http start
service http status - Check the port number on which Http is running
By default, web servers like Nginx & Apache httpd runs on the default 80 port. If you've already started Nginx on your machine, you have to stop it first in-order to start the Http server.
The alternative would be by changing the port numbers. It's recommend and a best practice if you're running on default port 80 if you're running only specific web-server at a time.
netstat -tnlp
You can see the server running on your machine by providing the url: localhost:80 or just localhost. - Change the configuration in Http
Go to /etc/http/conf.d You can find few configurations files here. We have to create a new file(default-sites.conf) and append the proxy configuration.
cd /etc/http/conf.d
touch default-sites.conf
Append the below configuration in this file.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
Save the file and exit. - Restart the serverlocalhost:80 or just localhost
Restart the server and visit the following address from your web browser.
Now, you'd be able to see the Jenkins page opening instead of Apache Http home page.
I'm glad that it helped you!!
ReplyDelete