October 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 ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Configure Nginx to Listen on Multiple Ports

Configure one Nginx HTTP server block to listen on multiple ports, or split ports into separate blocks when their settings or default handling differ.

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.

To make an Nginx HTTP server accept connections on more than one port, add a listen directive for each address-and-port endpoint inside its server block. Use one block when the ports should share the same configuration; use separate blocks when their behavior needs to differ.

Use one server block when both ports serve the same site

Add each port with its own listen directive. For example, this configuration applies the same virtual-server settings to requests arriving on ports 80 and 8080:

As an Amazon Associate I earn from qualifying purchases.

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

    root /var/www/example;
}

The HTTP listen directive specifies the address and port on which a server accepts requests. A server block can contain multiple such directives, describing the endpoints on which that configuration is available.

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

Use separate blocks for port-specific behavior

If a port needs different settings, route requests to separate server blocks by giving each block its own listen directive and configuration. Nginx first matches the connection’s destination address and port, then compares the request’s Host header with the server_name values among the matching servers. If no name matches, it uses the default server for that address-and-port pair. See the request processing documentation.

For example, the following assigns different defaults on ports 80 and 8080:

server {
    listen 80 default_server;
    listen 8080;
    server_name example.org;
}

server {
    listen 80;
    listen 8080 default_server;
    server_name example.net;
}

default_server is associated with a specific address-and-port pair, not with a server name. If no server for a pair declares it, the first server configured for that pair is the default. The server names documentation shows how defaults can differ by port.

Choose the address and address family

A port-only directive such as listen 8080; is appropriate when you want to use the applicable wildcard address. To bind to a particular interface, specify its address and port, for example listen 127.0.0.1:8000; or listen 192.0.2.10:8080;. The HTTP directive also accepts an address without a port; in that form, the documented port is 80.

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

For IPv6, enclose the literal address in brackets: listen [::]:8080; or listen [::1]:8080;. The documented ipv6only option defaults to on for an IPv6 wildcard socket, so do not assume that an IPv6 listener also accepts IPv4 connections. Confirm the behavior and reachability on the host and deployment where Nginx runs. The HTTP core documentation describes the supported listener forms and options.

Rank #3
Forvencer Server Book, 2 Zipper Pocket, Server Books for Waitress
  • Upgraded Two Zipper Pockets: Forvencer server books feature two secure zipper pockets for better organization of coins, cash, and receipts, ensuring that everything you collect has a safe and secure place
  • Smart Storage & Quick Access: Designed with 8 multi-functional compartments, the right side includes a guest receipt pad, while the left has a money pocket, ticket pocket, and credit card slot. Two small clear pockets store bills, receipts, and other visible items. A stitched pen loop ensures you always have your favorite pen ready
  • High-quality & Easy to Clean: Crafted from high-quality PU leather with heavy-duty stitching, this server book is built to last. It resists tears, scratches, and its waterproof surface makes cleaning easy with just a damp cloth or a non-chlorine sanitizer
  • Perfect Fit for Your Apron: Measuring 5” x 8”, this compact organizer is slightly smaller than other models, making it ideal for bending or sitting while carrying in your server apron. It holds everything a waitress needs—a place for everything
  • What's Included: This server organizer comes with multiple open and zippered pockets to store money, receipts, tips, etc. Clear sleeves are perfect for keeping menus or special lists while serving. Available in a variety of colors, allowing you to express yourself even when in uniform

Nginx can also listen on a UNIX-domain socket, using a path such as listen unix:/var/run/nginx.sock;. This is a socket endpoint, not a TCP port.

Test the configuration before applying it

  1. Edit the relevant HTTP configuration and add the required listen directive or directives to the intended server block.

  2. Run nginx -t. Nginx documents this option as checking configuration syntax and attempting to open files referenced by the configuration. See the command-line switches reference.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. If the test succeeds, reload Nginx using the procedure documented for the service manager and installation on your host. There is no single reload command that applies to every environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep protocol and version differences in mind

This configuration applies to HTTP server blocks. Nginx’s stream and mail modules have separate listener directives and protocol-specific behavior. In particular, the stream module documents port-range syntax; do not apply stream-specific syntax to an HTTP listen directive. The stream module documentation covers its listener separately.

Optional HTTP listener parameters can vary by Nginx version. The current HTTP core documentation notes that the http2 listen parameter is deprecated in favor of the http2 directive, while QUIC support is configured separately. Check documentation for the version installed on your server before adopting optional parameters. A valid Nginx configuration also does not by itself establish that a port is reachable from outside the host: interface availability, firewall rules, cloud security groups, and network routing depend on the deployment.

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 *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.