Benefits of using nginx as a reverse proxy

iot
Success Story / Tips

Benefits of using nginx as a reverse proxy

NGINX is 2.5 time faster than Apache based on the benchmark test running up to 1,000 concurrent connections. Apache benchmark running with 512 concurrent connections, For a static content NGINX is king when come to dynamic content apache will be doing slightly better job than nginx, this is many reason for using nginx as reverse for proxy to apache. 

Increased Security:  Reverse proxy also act as a defense for backend server, configuring your reverse proxy makes your backend server unknown.

Better Performance: As known nginx servers static content better than apache, With the nginx proxy all the static content will be handled by nginx meanwhile request for dynamic content can be. Passed on the backend server, This improves performance by optimizing the delivery of assets based on their type,

How to install and configure on ubuntu 16.04

sudo apt-get install apache2
sudo nano /etc/apache2/ports.conf
change listen port 80 to 8080

sudo nano /etc/apache2/sites-available/000-default.conf
change to sudo service apache2 reload

check apache listen on port 8080 by below command sudo netstat -tlpn

Install Nginix

sudo apt-get install nginx
Remove default site
sudo rm /etc/nginx/sites-enabled/default

configure site directory sudo mkdir -v /usr/share/nginx/{example.com,sample.org}

create proxy site for apache2 sudo nano /etc/nginx/sites-available/{example.com,sample.org}

server {
listen 80;
server_name example.com www.example.com; # replace with your site’s
location / {
proxy_pass http://localhost:8080;
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;
}
}

Enable your site, sudo ln -s /etc/nginx/sites-available/{example.com,sample.org} /etc/nginx/sitesenabled/{example.com,sample.org}sudo

Test configuration
service nginx configtest

Restart the nginx
sudo service nginx reload

Reference Link