Configuring Nginx as a Reverse Proxy
1. Create a small express app
-
Install nodejs
and npm
on ubuntu
-
Create a project dir and initialize a node app
-
Install basic dependencies
-
Update the package.json
-
Create an `index.js1 file and add the following code
-
Install pm2
to run this dummy app in the background
-
Run the application with the following command:
This will start the application on port 8080
.
2. Do a reverse proxy with nginx
Nginx can also act as a reverse proxy, forwarding client requests to other servers.
-
Edit your server block configuration:
-
Configure the server block to act as a reverse proxy:
-
Test and reload Nginx:
Now, when you request http://<server_ip>/api
it will return the following response: