Configuring an Nginx reverse proxy involves changing some settings in the Nginx configuration file to allow it to take HTTP requests and to transfer them to a server behind the proxy.
Follow the steps below to configure Nginx reverse proxy:
Step 1: Install Nginx server on your VPS. In case if you have not installed it yet, you can use the following commands based on your OS
For Ubuntu/Debian:
```
sudo apt-get update
sudo apt-get install nginx
```
For CentOS/Fedora:
```
sudo yum update
sudo yum install nginx
```
Step 2: After installation, Start the Nginx service
```
sudo service nginx start
```
Step 3: After running the Nginx server, you need to go to the Nginx configuration directory and update the Nginx configuration file (`/etc/nginx/nginx.conf`or `/etc/nginx/sites-available/default`).
Step 4: Let’s assume that the server (the one you want the Nginx to be a reverse proxy for) is running on `localhost` port `8080`.
Open the Nginx configuration file:
```
sudo nano /etc/nginx/sites-available/default
```
And add these under `location /` setting:
```
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
```
This tells that for every HTTP request Nginx gets, it would transfer that to `http://localhost:8080`.
Step 5: After changing the configuration file, you need to test the configuration syntax:
```
sudo nginx -t
```
Step 6: If the syntax is okay, then restart the Nginx service:
```
sudo service nginx restart
```
Step 7: Now your Nginx server is setup to direct traffic from your domain to `http://localhost:8080`.
Please replace `http://localhost:8080` with the IP address and port where your application is running. Similarly, replace `/etc/nginx/sites-available/default` with your Nginx’s default server block or create a new one under `sites-available` and create a symbolic link in `sites-enabled`. Also, don’t forget to allow traffic through port `80` on your firewall if you have one.
Keep in mind that `sudo` command might ask for your user password, this user must be a `sudoer`.
Note: The process may differ based on your VPS provider and the Operating System of your server.