Steps to install Nginx reverse proxy on Ubuntu 18.04

install Nginx reverse proxy on Ubuntu

Distributing the load among several servers is proxying. To reduce latency, reverse proxy act as a cache or buffer. User access control is simplified as you need a single point of access to your site. It serves as a proxy server between internal applications and external clients.

To protect backend resources the Nginx reverse proxy will navigate via the firewall. It intercepts the client’s request and routes them to a selected proxy server. Then, send the server response to the client. This will let you proxy requests to various web servers. Now let’s see the steps to install and configure Nginx reverse proxy on Ubuntu 18.04.

Nginx Installation

Nginx Installation

Below is the process to install Nginx,

  • First, ensure that you have a fresh installation of Ubuntu 18.04 on your server.
  • Following that, install all the updates and reboot to use new kernels.
apt update && upgrade -y
reboot
  • You can easily install the Nginx web server by using the below command:
apt install nginx -y     
  • Once after the installation, you can now enable the service to start on every boot.
systemctl start nginx.service
systemctl enable nginx.service

Nginx Reverse Proxy Configuration          

  • To configure the reverse proxy setting, open /etc/nginx/sites-available/default in any editor.
  • Now add your upstream server (behind the proxy, these web servers will serve your website).

Use the below upstream server as an example:

upstream website 
{
server http://192.168.1.30;
}             

Note: If you have local DNS configured, you can avoid using the IP address.

  • When you modify the server definition, the Nginx will proxy your request.
server {
listen 80;
server_name domainname;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
 proxy_pass http://website;
}
}
  • Once finished executing the command, you can save and exit the file.

By using the below command, you can check the Nginx configuration:

nginx –t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful           
  • Now restart the Nginx web server. 
systemctl restart nginx.service          

Hope it was helpful, if you need any assistance feel free to reach us – Get Support

Also read: 502 Bad Gateway error in Nginx – Fix It
Nginx on cPanel – Quick setup guide of Engintron

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Written by actsupp-r0cks