Back to lessons

Hosting Operations

Map Nginx Proxy Targets

You need to see where Nginx forwards proxied requests.

Command

grep -RInE '^[[:space:]]*proxy_pass[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

What changed

Nothing changes. The command lists proxy_pass targets.

Danger

safe

When to use it

Use when 502s, stale apps, or wrong backends suggest a proxy target problem.

When not to use it

Do not assume the upstream process is running just because the config points to it.

Undo or recovery

No undo needed because this command is read-only.

Expected output

Config paths and proxy_pass target URLs.

demo script

Disposable terminal steps

  1. grep -RInE '^[[:space:]]*proxy_pass[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
  2. grep -RInE 'proxy_set_header[[:space:]]+Host' fixtures/nginx/conf.d fixtures/nginx/sites-enabled

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ grep -RInE '^[[:space:]]*proxy_pass[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
fixtures/nginx/conf.d/admin.conf:6:        proxy_pass http://localhost:9100;
fixtures/nginx/sites-enabled/example.conf:16:        proxy_pass http://127.0.0.1:9000/;
::exit-code::0
$ grep -RInE 'proxy_set_header[[:space:]]+Host' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
fixtures/nginx/sites-enabled/example.conf:15:        proxy_set_header Host $host;
::exit-code::0

YouTube Short

Where is Nginx proxying?

For 502s, check the proxy target before restarting services. Nginx may be forwarding to the wrong port.

LinkedIn hook

Nginx was healthy. It was proxying to the wrong place.

Question: For a 502, do you inspect proxy_pass before checking the app process?

experiments

A/B tests to run

Metric: watch_time

A: Wrong proxy target.

B: Find proxy_pass before restart.