Understanding Proxies: Forward vs Reverse


π Introduction
Whether you're building modern web apps or exploring computer networking as a CS student or developer, you've likely encountered proxy serversβespecially while dealing with CORS errors or setting up dev environments.
But what exactly is a proxy server? Why are there forward and reverse proxies? And how do you use one effectively in a React (Vite) app?
Letβs break it all down β the what, why, and how, with developer-friendly explanations and real-world setups.
π§ What is a Proxy Server?
A proxy server acts as an intermediary between a client (like your browser or frontend app) and a destination server (like an API or a website). Instead of sending your request directly to the target, your request first goes to the proxy, which forwards it to the actual server.
Think of it as a digital middleman that routes your traffic behind the scenes.
π Types of Proxies: Forward vs Reverse
β€ 1. Forward Proxy
π Position: Between the client and the internet/server
π₯ Use Case: Helps clients access resources indirectly (common in schools, organizations, or VPNs)
π‘ Example:
A university blocks YouTube, but you use a forward proxy to access it.
You use a proxy in development to bypass CORS errors when calling external APIs.
πΌοΈ Visual:Client β [Forward Proxy] β Server
graph TD
A[Client] --> B[Forward Proxy Server]
B --> C[Target Server]
β€ 2. Reverse Proxy
π Position: Between the internet/client and the server
π€ Use Case: Routes incoming requests to appropriate backend services, load balances traffic, hides internal services.
π‘ Example:
Nginx receives traffic at
example.com/api
and forwards it to your Node.js API server.Used in microservices architecture, CDN, or API gateways.
πΌοΈ Visual:Client β [Reverse Proxy] β Multiple Internal Servers
graph TD
A[Client/ User] --> B[Reverse Proxy e.g Nginx]
B --> C[Web Server e.g React frontend ]
B --> D[API Server e.g Node/Express]
B --> E[Auth Service e.g JWT/OAuth]
π§βπ» Why Proxies Matter for Developers
As a frontend dev or full-stack engineer, you may use proxies to:
Avoid CORS issues in development.
Route API calls through a local server.
Keep environment configurations clean.
Simulate real-world API architecture.
βοΈ Proxy Setup in React (Vite)
Letβs say you have a React app created with Vite and a backend API running at http://localhost:5000
. You want to fetch data from /api/users
.
π§ͺ Problem:
If your frontend is on localhost:5173
, calling fetch('
http://localhost:5000/api/users
')
will trigger a CORS error.
β Solution: Use Viteβs Dev Proxy (Forward Proxy)
Vite provides a clean proxy option in vite.config.js
.
π§ Step-by-Step Setup
Modify vite.config.js
:
// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/api': {
target: 'http://localhost:5000', // Your backend server
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
}
})
Fetch API in your frontend:
// src/App.jsx
import { useEffect, useState } from 'react'
function App() {
const [users, setUsers] = useState([])
useEffect(() => {
fetch('/api/users') // This will be forwarded to http://localhost:5000/users
.then(res => res.json())
.then(data => setUsers(data))
}, [])
return (
<div>
<h1>Users</h1>
<ul>
{users.map((user, i) => <li key={i}>{user.name}</li>)}
</ul>
</div>
)
}
export default App
Start your backend and frontend:
# Backend on port 5000
# Frontend on port 5173
npm run dev
β Done! Youβve just set up a forward proxy using Vite!
π What About Reverse Proxy?
While Vite helps during development, reverse proxies like Nginx or Apache are often used in production to:
Serve React app statically.
Forward
/api/*
calls to the backend server.Provide SSL termination (HTTPS).
Load balance between multiple backends.
π Sample Nginx Config for React + Node:
nginxCopyEditserver {
listen 80;
server_name yourdomain.com;
location / {
root /var/www/react-app;
index index.html;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://localhost:5000/;
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;
}
}
π¬ Common Questions
β Why not call the backend directly from React?
Because of CORS restrictions. Browsers prevent JS from calling a different origin. A proxy acts as a workaround.
β Can I use reverse proxy in development?
You can, but it's overkill. Vite's forward proxy is optimized for DX (Developer Experience).
π Summary
Proxy Type | Positioned Between | Use Case |
Forward Proxy | Client β Proxy β Server | CORS fix, access control, VPN |
Reverse Proxy | Client β Proxy β Backend | API routing, load balancing |
π§© Bonus: Debugging Tips
Use
console.log(req.headers)
on backend to inspect forwarded headers.Use browser dev tools β Network tab β check if
/api/*
is being redirected.Use tools like
http-proxy-middleware
if using CRA instead of Vite.
π Final Thoughts
Understanding proxies is a crucial skill for every web developer and computer science student. Whether youβre fixing a CORS issue or deploying to production, proxies are your silent helpers behind the scenes.
β Start with forward proxy in Vite, then explore reverse proxies like Nginx for production-level control.
If you found this blog helpful, do share it with your developer friends. Got questions or feedback related to the topic? Drop them in the comments β Iβd love to discuss!
Stay tuned for more such deep-dives. Until then, keep building and keep learning. π
Subscribe to my newsletter
Read articles from Anuj Kumar Upadhyay directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Anuj Kumar Upadhyay
Anuj Kumar Upadhyay
I am a developer from India. I am passionate to contribute to the tech community through my writing. Currently i am in my Graduation in Computer Application.