Guide: Nginx as Frontend, Apache2 as Backend on Debian LXDE

1. Update Your System

Open your terminal and update packages:

sudo apt update && sudo apt upgrade -y

2. Install Apache2

Apache will act as the backend server that actually serves the content.

sudo apt install apache2 -y

Verify Apache is running:

systemctl status apache2

If it’s not running, start and enable it:

sudo systemctl start apache2 sudo systemctl enable apache2

Test: Open your browser and go to
๐Ÿ‘‰ http://localhost
You should see the Apache default page.


3. Change Apache Listening Port

Since Nginx will listen on port 80, Apache must use a different port (e.g., 8080).

Edit the ports configuration:

sudo nano /etc/apache2/ports.conf

Change:

Listen 80

to:

Listen 8080

Then edit the default Apache site config:

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

Find the line:

<VirtualHost *:80>

Change it to:

<VirtualHost *:8080>

Save and restart Apache:

sudo systemctl restart apache2

Test backend:
๐Ÿ‘‰ Open http://localhost:8080
Apache should now be serving content on port 8080.


4. Install Nginx

Nginx will act as the frontend (reverse proxy).

sudo apt install nginx -y

Start and enable it:

sudo systemctl start nginx sudo systemctl enable nginx

5. Configure Nginx as Reverse Proxy

Create a new Nginx site config:

sudo nano /etc/nginx/sites-available/apache-proxy

Add the following:

server { listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1: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; proxy_set_header X-Forwarded-Proto $scheme; } }

Save and enable the config:

sudo ln -s /etc/nginx/sites-available/apache-proxy /etc/nginx/sites-enabled/

Remove the default config if you don’t need it:

sudo rm /etc/nginx/sites-enabled/default

6. Test and Restart Services

Check Nginx configuration for syntax errors:

sudo nginx -t

If everything is OK, restart Nginx:

sudo systemctl restart nginx

7. Verify Setup

Now open your browser and visit:
๐Ÿ‘‰ http://localhost

  • The request goes to Nginx (frontend) on port 80.

  • Nginx forwards it to Apache (backend) on port 8080.

  • You should see the Apache page delivered through Nginx.


8. (Optional) Firewall Adjustments

If you are running ufw, allow HTTP traffic:

sudo ufw allow 'Nginx Full'

✅ You now have Apache2 running as the backend and Nginx as the frontend reverse proxy on Debian LXDE.

Comments

Popular posts from this blog

Protecting Your Brand’s Email Reputation: Why Your Business Needs DMARC

Setup to enable HTTPS with Let’s Encrypt SSL certificates on Nginx (frontend), while Apache remains the backend.