Your First Proxy Host
The outcome of this chapter is the moment the whole product exists for: one of your services, reachable by a name you chose instead of an address and a port. You will fill in the proxy host form once, slowly, because every field on it is a decision the generated configuration will carry out — and then chapter 6 opens the result.
Before the form: the name. A proxy
host begins in DNS, not in NPM. The
name you use (app.example.com in
this guide's examples) must resolve to
the machine running NPM — an A
record at your DNS provider for a
public name, or an entry in your home
router's or DNS server's local zone
for a private one. NPM cannot fix a
name that points somewhere else, and
neither the proxying nor the
certificate of chapter 8 will work
until it points here. Check with
dig +short app.example.com from
another machine and expect this
machine's address back.
The form. In the admin interface: Hosts → Proxy Hosts → Add Proxy Host. The Details tab asks for:
- Domain Names — one or more names this host answers to. Type a name, press Enter, repeat for aliases.
- Scheme —
httporhttps: how NPM should talk to your service behind the scenes. Most home services are plainhttpon the LAN even when the public side will be HTTPS. - Forward Hostname / IP — where the
service actually lives
(
192.168.1.50, or a container name if the service shares a Docker network with NPM). - Forward Port — the port it
listens on (
8080in the lab's example). - Cache Assets, Block Common Exploits, Websockets Support — three switches. Block Common Exploits is on for this guide's host: it adds a filter file that refuses requests carrying classic attack patterns. Websockets Support matters for services with live-updating pages; leave it off until one needs it — chapter 12 has the recipe.
- Access List — None for now; chapter 10 is devoted to these.
Save. NPM writes the record to the database, generates the nginx file, has nginx test it, and reloads. The host's row reports it Online when all of that succeeded.
What the lab did instead of clicking — the same act, through the API (transcript t07), which is what the interface itself does behind the form:
curl -X POST http://127.0.0.1:81/api/nginx/proxy-hosts \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"domain_names":["app.example.com"],
"forward_scheme":"http",
"forward_host":"127.0.0.1",
"forward_port":8080,
"block_exploits":true,
"certificate_id":0,"access_list_id":0}'
In the lab the record was saved and
the file generated — and the request
still returned an error, because the
reload step had no running nginx to
talk to in the sandbox. The host sat
in the database with
"nginx_online": true from the
test step and no live server behind
it. Hold that story for chapter 6 and
the troubleshooting chapter: in a
Docker install the reload has its
companion nginx waiting, and the same
sequence ends with Online.
The check: from another machine,
request the name — curl -s
http://app.example.com — and expect
your service's own response, not an
NPM page and not an error. Then look
at Hosts → Proxy Hosts and confirm
the status is Online. If the name
answers with the wrong service or the
row says Offline, chapter 6's reading
of the generated file is how you find
out which part disagreed.