HTTP Proxies

Dr. Greg Bernstein

Updated November 13th, 2021

HTTP Proxies: Theory and Applications

Proxies

  • IETF Definition
    • An intermediary program which acts as both a server and a client for the purpose of making requests on behalf of other clients.

Proxy Types

From Wikipedia Proxy Server

  • A forward proxy is an Internet-facing proxy used to retrieve data from a wide range of sources. Used for monitoring, content filtering, bypassing filters and censorship, caching, and more.

  • A reverse proxy is an internal-facing proxy used as a front-end to control access to servers on a private network. Common tasks include: load-balancing, authentication, decryption or caching.

Reverse Proxies and Node.js Deployments

References

General Diagram

Reverse Proxy Block Diagram

Reverse Proxy Operation

Reverse proxy forward HTTP requests to different machines/processes based on parts of the URL

  • Domain names (and subdomains!)
  • Path (we’ll be using this)
  • Protocol (HTTP, HTTP, version)
  • Other

Reverse Proxy Single Machine

Reverse Proxy Single Machine

Example: Reverse Proxy for CSOARS

  • The “CS Oriented Audience Response Systems” (CSOARS) is a Node.js application
  • URL: https://classroom.grotto-networking.com
  • “Front end” Webserver: NGINX

Reverse Proxy Configuration CSOARS

NGINX configuration file (partial)

server {
        server_name classroom.grotto-networking.com;

        location / {
        proxy_pass http://localhost:21146; # Internal port for CSOARS
        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;

        }
        # More configuration stuff such as ports and
        # HTTPS stuff
}

Reverse Proxy Configuration: DrBsClasses.org

Apache2 configuration file (partial)

<Location "/student39/node" >
     ProxyPreserveHost On
     ProxyPass http://127.0.0.1:3039
     ProxyPassReverse http://127.0.0.1:3039
</Location>
<Location "/student40/node" >
     ProxyPreserveHost On
     ProxyPass http://127.0.0.1:3040
     ProxyPassReverse http://127.0.0.1:3040
</Location>

Proxies for Development

Proxies in Development 1

We will want to use proxy functionality in development:

Proxies in Development 2

  • We will write our own application server to give and process data from our web app.

  • We will combine our bundler (Parcel.js) with and Express.js server and additional middleware.

Proxies in Development 3

Need Specifics on Addresses and Ports

Proxies with ParcelV2

The .proxyrc.json File

From Parcel: API-proxy

{
  "/api": {
    "target": "http://localhost:8000/",
    "pathRewrite": {
      "^/api": ""
    }
  }
}

"This example would cause http://localhost:1234/api/endpoint to be proxied to http://localhost:8000/endpoint.

Simpler .proxyrc.json File

{
    "/members": {
      "target": "http://localhost:5001"
    }
}

This would map the relative request of /members to http://loalhost:5001/members.

// reveal.js plugins