Skip to main content

Configurign NGINX as reverse proxy

1. Install NGINX

// debian based
apt-get install nginx

// RHEL
yum install nginx

2. Starting NGINX

Run the following to start NGINX.

systemctl start nginx

To check NGINX status run the following command.

systemctl status nginx

Output: Nginx status output

Enable NGINX to automatically start on instance reboot.

systemctl enable nginx

3. Configuring NGINX

Make directories named sites-available and sites-enabled inside /etc/nginx/ if not present

mkdir -p /etc/nginx/sites-available
mkdir -p /etc/nginx/sites-enabled

Check if the following line is present in the /etc/nginx/nginx.conf file. If not add the following:

include /etc/nginx/sites-enabled/*;

Now, create a file named <your-full-domain> inside /etc/nginx/sites-available.

touch /etc/nginx/sites-available/<your-full-domain>

Add the following to the file:

server {
listen 80;
listen [::]:80;

server_name <your_domain> www.<your_domain>;

location / {
proxy_set_header Host $host;
proxy_pass http://<local service address>:<port>
}
}

Create symlink for the above file inside /etc/nginx/sites-enabled

ln -s /etc/nginx/sites-available/<your-full-domain> /etc/nginx/sites-enabled/

4. Test NGINX config

nginx -t

Output: Nginx test output

5. Restart NGINX

Run the following command to restart NGINX and apply the changes

systemctl restart nginx