Configure NGINX as a reverse proxy |In this tutorial
we learn how to configure NGINX as a reverse proxy to improve performance and security
enhancement and other feature of NGINX server is that it acts as a load
balancer also.
Lab environment
We have one
reverse proxy server.
Reverse Proxy server ipaddress ================>192.168.137.2
Hostname of proxy server==============>
proxy.example.com
We have one web server .
web server ip address
===============>192.168.137.3
hostname of webserver ==============>web.example.com
and put the host file entry if you don’t
have any dns server like this.
[root@proxy]# cat /etc/hosts
192.168.137.2
proxy.example.com
192.168.137.3
web.example.com
configuration of webserver
Before
configuration of proxy server first we have to configure a sample web server to
demonstrate. For this we use apache web server. First we install httpd package
and configure it and create a sample index.html file . to do this follow the
below step.
To install
apache web server we execute the below command.
#yum
install httpd
After
installing the httpd server start the service and on the startup mode using the
below command.
#service
httpd start;chkconfig httpd on
Now create
a sample index.html file execute the below command
#echo
“welcome to techrideradmin.blogspot.com” > /var/www/html/index.html
Now web
server configuration part is over . now we are going to configure the proxy server
and verify it.and this server is running 8080 port
[root@web ~]# curl http://192.168.137.3:8080
“welcome to techrideradmin.blogspot.com”
[root@web ~]# curl http://192.168.137.3:8080
“welcome to techrideradmin.blogspot.com”
configuration of reverse proxy
To
configure NGINX reverse proxy we need to install NGINX on your linux
machine .
See the
reference to install the NGINX on linux system
after
installing the NGINX we go to the configuration file of the NGINX server which
is located at “/etc/nginx/conf.d/default.conf” .
we remove the default configuration file using the below command.
#rm /etc/nginx/conf.d/default.conf
and create a new file named "proxy.conf".
we remove the default configuration file using the below command.
#rm /etc/nginx/conf.d/default.conf
and create a new file named "proxy.conf".
How to configure NGINX as a reverse proxy on linux step by step guide
And add the
following lines
server {
listen 80;
listen [::]:80;
server_name proxy.example.com;
location / {
proxy_pass http://192.168.137.3:8080/;
}
}
listen 80;
listen [::]:80;
server_name proxy.example.com;
location / {
proxy_pass http://192.168.137.3:8080/;
}
}
After doing this we check using the below command from the reverse proxy server.
[root@proxy ~]# curl http://192.168.137.2
“welcome to techrideradmin.blogspot.com”
That’s all.Now
NGINX acts as reverse proxy which hide the the origin or source of the backend server thus the server is secure from the outside world..
0 comments:
Post a Comment