Run the following on the public-facing EC2 (nginx) instance.
once chek in your config file below one is comented or uncomented if commented please uncoment and build the package
const backendIP = ""; // For reverse proxy it is mandatory and keep it empty dont pass anty url or ip here
sudo yum update -y
sudo yum install -y nginx
# Enable and start nginx
sudo systemctl enable --now nginxcreate a proxy file and paste the file from git and chage the backend private ip if you are using internal loadbalncer change it
sudo vi /etc/nginx/conf.d/reverse-proxy.confserver {
listen 80;
server_name _;
# 🔥 Proxy users endpoints directly
location /users {
proxy_pass http://172.31.27.126:5000;
proxy_http_version 1.1;
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;
proxy_redirect off;
}
# React / HTML frontend
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
# React build
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
- Test and reload nginx:
sudo nginx -t
sudo systemctl reload nginxsudo cp index.html /usr/share/nginx/html/
sudo systemctl reload nginx