Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Point Subdomains to Specific Ports With Nginx

DNS maps subdomains to hosts, not ports. Configure Nginx server blocks and proxy_pass rules to route each hostname to the correct private application port, then add HTTPS and validate the setup.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

DNS cannot point a subdomain to port 3000, 8080, or any other application port. DNS records resolve a name to an IP address or another hostname. Nginx receives the request on a public listener—normally HTTP port 80 or HTTPS port 443—chooses a virtual server with server_name, and sends the request to the required internal service with proxy_pass.

For example, app1.example.com can reach an application listening on 127.0.0.1:3000, while app2.example.com reaches another service on 127.0.0.1:8080. Visitors use clean URLs without exposing either backend port.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The three layers that make subdomain-to-port routing work

A reliable setup separates name resolution, public request handling, and application delivery.

1. DNS resolves the hostname

At your authoritative DNS provider, create a record for each subdomain. An A record maps a name to an IPv4 address; an AAAA record maps it to an IPv6 address; and a CNAME aliases the name to another fully qualified domain name. None of these records contains an application port.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

For a server with IPv4 address 203.0.113.10, the records might look like this:

Name Type Value Purpose
app1 A 203.0.113.10 Resolves app1.example.com to the Nginx host
app2 A 203.0.113.10 Resolves app2.example.com to the same Nginx host
app1 AAAA Your Nginx host’s IPv6 address Provides IPv6 resolution when the server supports it
app2 CNAME edge.example.net Aliases app2.example.com to another hostname when that is your DNS provider’s recommended model

Use the subdomain label, such as app1, in the DNS name field if the provider automatically appends example.com. Some interfaces require the complete hostname instead. Check the result with dig app1.example.com and dig app2.example.com; each answer should lead to the machine running Nginx, not to an inaccessible private address.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Nginx listens publicly and selects a server block

Nginx normally accepts HTTP on port 80 and HTTPS on port 443. The hostname in the request is compared with each block’s server_name. An exact name is the clearest choice for separate applications. If no name matches, Nginx uses the default server for that listening address and port.

3. proxy_pass selects the application port

Inside a matching location, proxy_pass specifies the upstream protocol, address, and port. Nginx sends the request to that upstream, receives the response, and returns it to the browser. The applications can remain bound to loopback or a private network while only ports 80 and 443 are exposed publicly.

Prerequisites and a safe network layout

  • A domain whose DNS you can edit, with each intended subdomain identified.
  • A server reachable from the Internet where Nginx is installed and running.
  • Applications listening on known addresses and ports, such as 127.0.0.1:3000 and 127.0.0.1:8080.
  • Firewall and cloud security-group rules allowing public TCP 80 and, for HTTPS, TCP 443.
  • Permission to edit Nginx configuration and reload its service.
  • For HTTPS, a certificate and private key covering every hostname you will serve.

Do not open backend ports merely to make proxying work. If Nginx and the applications share a machine, bind the applications to 127.0.0.1. If they run on separate machines, use private addresses and restrict access so only the Nginx host can reach the upstream ports.

Configure DNS before debugging Nginx

  1. Open the authoritative DNS zone for example.com.
  2. Create an A record named app1 whose value is the Nginx server’s public IPv4 address.
  3. Create an A record named app2 with the same address when both names use that Nginx host.
  4. Add AAAA records only when the Nginx host has a working IPv6 address and firewall path. An AAAA record pointing at an unusable IPv6 endpoint can make some clients fail even when IPv4 works.
  5. Use a CNAME instead of an A or AAAA record when the subdomain must alias another hostname and your DNS provider supports that arrangement.
  6. Wait for the record’s TTL and query each name with dig. Confirm the returned address is the intended public endpoint.

DNS propagation does not configure Nginx and does not select port 3000 or 8080. It only determines where the client’s connection begins.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Basic HTTP configuration for two subdomains

Create one server block per hostname. The following example exposes both services on port 80 and keeps their application ports private:

server {
    listen 80;
    server_name app1.example.com;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:3000;
    }
}

server {
    listen 80;
    server_name app2.example.com;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:8080;
    }
}

Replace the names, addresses, and ports with your own values. The two blocks may share listen 80; Nginx distinguishes them by server_name. Keep the names exact unless you intentionally need a wildcard such as *.example.com.

Why the proxy headers are included

Nginx changes the proxied Host header to $proxy_host by default and sets Connection to close. Explicitly sending Host $host lets an upstream application see the hostname the visitor requested. X-Real-IP carries the client address, while X-Forwarded-For preserves the proxy chain. X-Forwarded-Proto tells an application whether the original request used HTTP or HTTPS.

Configure the application or framework to trust these headers only from your Nginx proxy. Blindly trusting client-supplied forwarding headers can allow incorrect addresses or protocol information to reach access-control, logging, and redirect logic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand proxy_pass path and trailing-slash behavior

The difference between a URI-bearing and URI-less proxy_pass matters when an application is mounted below a path.

Directive Request example Upstream URI Use when
proxy_pass http://127.0.0.1:3000; /users?id=4 /users?id=4 The upstream should receive the complete original path
proxy_pass http://127.0.0.1:3000/; inside location /app/ /app/users /users The matching /app/ prefix should be replaced
proxy_pass http://127.0.0.1:3000/api/; inside location /service/ /service/users /api/users The location prefix should become another upstream prefix

Nginx normalizes the request URI first. When proxy_pass includes a URI, it replaces the part that matched the location; without a URI, it forwards the full normalized request URI. Decide this deliberately, especially for single-page games, APIs, and asset paths where an unexpected prefix produces 404 responses.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Add HTTPS with certificates and SNI

For production traffic, terminate TLS at Nginx. A basic HTTPS block for the first application is:

server {
    listen 443 ssl;
    server_name app1.example.com;

    ssl_certificate     /etc/letsencrypt/live/app1.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app1.example.com/privkey.pem;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://127.0.0.1:3000;
    }
}

The listen 443 ssl directive enables TLS for this virtual server, and the certificate paths must point to readable files containing the certificate chain and private key. Create a corresponding 443 block for every other hostname, or use a certificate whose subject alternative names (SANs) cover all names. A wildcard certificate can cover an appropriate subdomain level when its scope matches your names.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Multiple HTTPS virtual servers can share one IP because TLS Server Name Indication (SNI) carries the requested hostname during the handshake. Nginx still needs the correct server_name and a certificate covering that name; otherwise clients receive a certificate warning or the default certificate.

Redirect HTTP to HTTPS

After HTTPS works, use a separate port-80 block to redirect the hostname:

server {
    listen 80;
    server_name app1.example.com;
    return 301 https://$host$request_uri;
}

Repeat the redirect for each hostname, or place several names in one block when they share identical redirect behavior. Keep the actual proxying configuration on port 443. Test the certificate and redirect before enforcing policies such as strict transport security.

Deploy the configuration step by step

  1. Verify the upstream first. On the Nginx host, confirm the service is listening with ss -ltnp or its own status command. A process that is stopped, bound to a different address, or listening on another port cannot be reached by Nginx.
  2. Create the DNS records. Point every subdomain at the public Nginx address and verify with dig.
  3. Write the server blocks. Use one exact server_name per application, a public listen port, the required proxy headers, and the correct proxy_pass target.
  4. Check syntax. Run nginx -t. Fix every reported error before reloading; a failed syntax check leaves the old configuration active.
  5. Reload Nginx. Use the host’s service manager, for example systemctl reload nginx, so existing connections can finish while the new configuration is read.
  6. Test locally with the Host header. Run curl -H 'Host: app1.example.com' http://127.0.0.1/. This isolates Nginx name matching from public DNS and external firewalls. Test the second name the same way.
  7. Test publicly. Request each HTTP and HTTPS URL from a client outside the server’s network. Confirm the response, redirects, certificate name, and application-generated links.
  8. Watch logs while testing. Nginx access and error logs show which block handled the request and whether the upstream connection failed.

Troubleshoot by symptom

Symptom Likely cause Checks and fixes
DNS returns no address Missing, incorrect, or not-yet-published record Query with dig; verify the authoritative zone, record name, value, and TTL.
The browser reaches another site Hostname does not match a block, or the default server is handling it Check the exact server_name, the requested Host header, and which block is marked default.
Connection refused or timed out Port 80/443 is blocked, Nginx is not listening, or the public address is wrong Check Nginx status, listening sockets, host firewall, cloud firewall, and DNS results.
502 Bad Gateway Nginx cannot connect to the configured upstream Confirm the process is running, the address and port match, loopback/private routing works, and the upstream firewall permits Nginx.
404 from the application URI prefix was rewritten unexpectedly Compare the location and proxy_pass forms; remove or add the trailing URI deliberately.
Certificate warning Certificate does not cover the hostname, wrong certificate block selected, or incomplete chain Check SANs, certificate paths, exact server_name, SNI behavior, and the certificate chain.
Redirect loop or wrong absolute URLs Application does not know the original protocol Send X-Forwarded-Proto and configure the application to trust Nginx’s forwarding headers.
Correct service works locally but not publicly DNS or perimeter firewall issue Test locally with a Host header, then verify public DNS and that only the intended external ports are allowed.

Choose the right routing architecture

Architecture Public ports and IPs Backend exposure Certificate model Best fit
One Nginx host, many subdomains One IP; 80 and 443 Ports remain private on the same host Per-host, SAN, or wildcard certificate Several applications on one server
Nginx with private upstream machines One public IP; 80 and 443 Private network ports between Nginx and services Terminate TLS at Nginx or pass it upstream when required Separating frontend proxy from game, API, or admin servers
Separate public port per application May use one IP but exposes 3000, 8080, and others Backend ports are Internet-reachable unless filtered Each service may need its own TLS setup Special cases where the client must explicitly include a port
Path-based routing on one hostname One IP; 80 and 443 Private upstream ports One certificate for the hostname Applications that can tolerate URI prefix rewriting

Subdomain routing is usually easier to reason about than path routing because each application receives its own hostname and can keep its native root paths. Path routing can reduce the number of certificates and names, but it requires careful prefix handling and application awareness.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Operational and security details

Expose only what must be public

Permit inbound TCP 80 and 443 at the host and cloud firewall when those are the public listeners. Keep 3000, 8080, and similar service ports closed to the Internet unless a specific design requires direct access. Restrict private upstream traffic to Nginx and monitor for accidental listeners.

Keep names and defaults unambiguous

Use exact hostnames for production services. A wildcard can catch names you did not intend to publish, while an unmatched request goes to the default server. Create an intentional default server that rejects unknown hosts if your deployment needs strict isolation.

Plan certificate coverage before adding names

Each HTTPS hostname must be present in the certificate’s names. Decide whether separate certificates, one SAN certificate, or a wildcard certificate gives the right renewal and scope trade-off. Adding a DNS record alone does not make HTTPS valid.

Preserve the original request context

Host and forwarding headers affect redirects, cookies, logging, rate limits, and security checks. Pass them consistently and configure each application with the correct trusted-proxy setting. If an upstream does not need a header, do not invent a substitute value.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload safely

Always run nginx -t before a reload and retain a known-good configuration. A syntax failure prevents the new file from loading; an upstream failure passes the syntax check but appears as a 502 during requests, so application health checks remain necessary.

Common mistakes to avoid

  • Trying to put :3000 or :8080 into an A, AAAA, or CNAME record. DNS records do not carry ports.
  • Pointing DNS directly at a private address such as 192.168.x.x or 10.x.x.x for an Internet-facing service.
  • Opening every backend port publicly instead of allowing Nginx to proxy privately.
  • Copying a 443 block without changing its server_name or certificate paths.
  • Omitting the trailing-slash decision when an application lives under a path prefix.
  • Assuming a successful nginx -t proves that the application is reachable; syntax validation does not test upstream connectivity.
  • Trusting X-Forwarded-For from arbitrary clients instead of only from the known proxy.
  • Testing only by IP address. Name-based routing depends on the Host header, so test the real hostname or send an explicit Host header.

A compact verification checklist

  • Each subdomain resolves with A, AAAA, or CNAME to the intended Nginx endpoint.
  • The application is listening on the exact address and port in proxy_pass.
  • Nginx has one correct server block for each hostname and listener.
  • Port 80 and, when used, port 443 are permitted through host and cloud firewalls.
  • Backend ports remain private unless direct public access is deliberate.
  • nginx -t succeeds before every reload.
  • Local Host-header tests reach the expected service.
  • Public HTTP and HTTPS tests show the expected content and certificate.
  • Logs distinguish name-selection problems from upstream 502 errors.
  • URI and trailing-slash behavior matches what the application expects.

Frequently Asked Questions

Can an A record point app.example.com directly to port 3000?

No. A and AAAA records contain addresses, and CNAME records contain hostnames. Put the port mapping in Nginx with a matching server block and a proxy_pass target.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Do all subdomains need separate IP addresses?

No. Multiple subdomains can resolve to one Nginx IP. Nginx selects the destination by server_name and can proxy each name to a different private port.

Why does Nginx return 502 when the application works in a browser on the server?

The proxy target may use the wrong address or port, the service may listen only on a different interface, or a private firewall may block Nginx. Verify the listening socket and the exact proxy_pass address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I use a trailing slash in proxy_pass?

Use it according to the desired URI mapping. Without a URI, Nginx forwards the full normalized path; with a URI, it replaces the part matched by location. Test a representative path before deploying.

Can several HTTPS subdomains share one IP?

Yes. TLS SNI lets Nginx choose among HTTPS virtual servers on one address, provided each server_name is correct and the selected certificate covers the requested hostname.

Which ports need to be open on the firewall?

For the normal reverse-proxy design, expose TCP 80 and 443 publicly as needed. Keep application ports such as 3000 and 8080 private when Nginx can reach them locally or over a protected network.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.