Nginx as reverse proxy

An NGINX reverse proxy acts as an intermediary between clients and backend servers, routing incoming traffic to the appropriate server based on URL, load balancing, and other criteria. This configuration enhances web application performance, improves security, and provides flexibility in managing traffic to various servers. 

 

 Install Nginx

sudo apt install nginx

 

Create Virtual Host Configuration /etc/nginx/sites-available/yourdomain.com.conf

     server {
         listen 80;
         server_name contoh.com;
         location / {
             proxy_pass http://localhost:8000; # Alamat server backend
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }
     }

 

Activate Virtual Host 

sudo ln -s /etc/nginx/sites-available/domain.com.conf /etc/nginx/sites-enabled/

 

Test Config

sudo nginx -t

 

Restart nginx

sudo systemctl restart nginx

 

Done.

Related Articles