Operations 5 min read

Mastering Forward and Reverse Proxies: When and How to Configure Nginx & Apache

This article explains the concepts of forward and reverse proxy servers, why organizations use them, and provides step‑by‑step configuration examples for both Nginx and Apache to help engineers enforce network policies and secure service access.

21CTO
21CTO
21CTO
Mastering Forward and Reverse Proxies: When and How to Configure Nginx & Apache

Introduction

Most of us are familiar with forward and reverse proxy servers. In the client (user‑agent) context you can see “forward” and “reverse”. Resources can be websites, server nodes, FTP servers, etc.

Why Use Proxies?

Example organization QWERTY defines policies: (1) Everyone accessing the Internet must follow organizational rules. (2) No one may directly access service nodes; all traffic must go through defined proxies.

How Does It Work?

Employees need to know which policies apply and whether they are allowed Internet access. A forward proxy forwards client requests to the intended node, enforcing policy. A reverse proxy sits in front of services, handling incoming traffic based on architectural decisions such as spam protection, attack mitigation, infrastructure updates, domain changes, service dependencies, and SSL certificate constraints.

Setting Up a Reverse Proxy

Nginx

Open nginx.conf (backup first) and add a location block in the server section:

......
server {
    listen <%= ENV["PORT"] %>;
    server_name localhost;
    //Any context‑path with "/api" will be served by api‑qwerty.com
    location /api {
        proxy_set_header Host api-qwerty.com:80;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://abc-def.ghij-klmn.com;
    }
    //Any context‑path with "/ui" will be served by ui‑qwerty.com
    location /ui {
        proxy_set_header Host ui-qwerty.com:80;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://ui-qwerty.com;
    }
}

Apache

Open httpd.conf (backup first) and add proxy directives:

....
ProxyPass /api http://api-qwerty.com/api
ProxyPassReverse /api http://api-qwerty.com/api
ProxyPass /ui http://ui-qwerty.com/ui
ProxyPassReverse /ui http://ui-qwerty.com/ui
....
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendProxyOperationsNGINXApachereverse-proxy
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.