Reverse proxy applications

Proxy to an application

Send requests to a local application and understand how the proxypass URI changes upstream paths.

8 minute lesson

~~~

A reverse proxy accepts the public request and makes a separate request to an upstream application.

proxy_pass can target a TCP address or Unix socket. A trailing URI changes how Nginx replaces the matched location prefix. Test the exact upstream path instead of guessing.

Run a local test application that prints its request path. Proxy /app/ to it and compare proxy_pass forms with and without a trailing slash.

Proxy one location to a local application:

location /api/ {
  proxy_pass http://127.0.0.1:3000/;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-Proto $scheme;
}

Test the application directly first, then through Nginx. Notice the trailing slash behavior in proxy_pass. Inspect both access logs and application logs so you can follow one request across the proxy boundary.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →