sudo apt install nginx
sudo rm sudo vi /etc/nginx/nginx.conf
sudo vi /etc/nginx/nginx.conf
For Linux
sudo yum install nginx
For Front End
After executing sudo vi /etc/nginx/nginx.conf
, the editor will open. Follow these steps:
Press
i
to enter insert mode.Paste the following lines into the file:
events {
# Event directives...
}
http {
server {
listen 80;
server_name ip_address or domain_name;
# Handle requests to the frontend
location / {
proxy_pass http://localhost:port_of_your_react_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
For Front End and Backend
events {
# Event directives...
}
http {
server {
listen 80;
server_name ip_address or domain_name;
# Handle requests to the frontend
location / {
proxy_pass http://localhost:port_of_your_react_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# Handle requests to the backend API
location /api/ {
proxy_pass http://localhost:port_of_your_react_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
After this Reload the nginx server
sudo systemctl restart nginx