Sitemap
Apache & Nginx

Mastering the Art of Setting Up Apache and Nginx Reverse Proxy on Your Debian VPS Server

2 min readAug 7, 2023

--

In today’s digital landscape, the ability to seamlessly manage and optimize server configurations is crucial for any web developer or administrator. As someone who is passionate about technology and always eager to learn, I embarked on a journey to demystify the intricacies of setting up an Apache and Nginx reverse proxy on my Debian VPS server.

In this guide, I’ll share my hands-on experience and insights, helping you navigate the process with confidence in few easy steps.

Step 1: Preparing the Groundwork

Before delving into the setup, it’s essential to ensure your Debian VPS is up-to-date. Connect to your server using SSH and run the following commands:

sudo apt update 
sudo apt upgrade

This ensures that you’re working with the latest software versions and security patches.

Step 2: Installing Apache

Apache is a battle-tested web server that will serve as our reverse proxy. Install it using:bashCopy code

sudo apt install apache2

Once installed, start the Apache service:

sudo systemctl start apache2

And enable it to start on boot:

sudo systemctl enable apache2

Step 3: Navigating Nginx

Next, we’ll integrate Nginx as our reverse proxy. This powerful server will handle incoming requests and distribute them to the appropriate backend servers.

Install Nginx with:

sudo apt install nginx

Start and enable Nginx:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Configuring Apache

Now, let’s configure Apache to work harmoniously with Nginx. We’ll need to enable the necessary modules and adjust the virtual host settings.

Open the default virtual host file:

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following lines within the <VirtualHost> section:

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Save the file and restart Apache

sudo systemctl restart apache2

Step 5: Orchestrating Nginx

With Apache ready, let’s configure Nginx to listen on port 80 and forward requests to Apache. Open Nginx’s default configuration:

sudo nano /etc/nginx/sites-available/default

Inside the server block, add the following:

location / {
proxy_pass http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Save and close the file, then restart Nginx:

sudo systemctl restart nginx

Congratulations, You’ve successfully set up an Apache and Nginx reverse proxy on your Debian VPS server.

Happy proxying!

--

--

Ashfaque Ali
Ashfaque Ali

No responses yet