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

To make an Nginx HTTP site accept connections on more than one port, add one listen directive for each address-and-port endpoint in its server block. For example, listen 80; and listen 8080; make the same server configuration available on both ports. Use separate blocks when requests on different ports need different settings or handling.

Choose one server block or separate blocks

A server block can listen on several ports. Nginx applies that block’s configuration to requests arriving through any of its configured endpoints. If the ports should serve different content or use different settings, define separate blocks instead. Nginx first matches the connection’s local address and port, then compares the request’s Host header with the eligible blocks’ server_name values. The HTTP core documentation describes the listen directive and its endpoint forms; the request-processing documentation explains server selection.

Configuration Use it when Effect
One block with multiple listen directives The ports should use the same virtual-server configuration. Requests on each configured endpoint share the block’s settings.
Separate blocks A port needs its own behavior, server names, or default handling. Each block can define its own settings and listening endpoints.

Configure the same site on multiple ports

Add a listen line for each port inside the HTTP server block. This example serves the same site configuration on ports 80 and 8080:

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

    root /var/www/example;
}

Keep the shared site settings, such as server_name and root, in that block. The HTTP core reference allows a server’s listen directives to specify all the addresses and ports on which it accepts requests.

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

Bind to a specific address or use IPv6

A port-only directive such as listen 8080; uses the applicable wildcard address. To bind a specific interface, give the address and port together. The HTTP directive also accepts an address without a port; the documented default in that form is port 80. Check that the chosen address exists on the host.

  • listen 127.0.0.1:8000; binds to the IPv4 loopback address, so the endpoint is local to the machine.
  • listen 192.0.2.10:8080; illustrates binding to a specific IPv4 address. Use an address assigned to your host, not this documentation-range example.
  • listen [::]:8080; binds an IPv6 wildcard endpoint.
  • listen [::1]:8080; binds to the IPv6 loopback address.

Put IPv6 literals in square brackets. The documented ipv6only setting defaults to on for an IPv6 wildcard socket; do not assume that an IPv6 listener also accepts IPv4 connections. Confirm address-family behavior and reachability for the host and deployment in use. See the listen directive reference.

Nginx can also listen on a UNIX-domain socket, for example listen unix:/var/run/nginx.sock;. That is a socket endpoint, not a TCP port.

Set different behavior and defaults by port

Use separate server blocks when each port needs different behavior. A default server is chosen independently for each address-and-port pair. If no block for a pair declares default_server, the first configured block for that pair is the default. For example, this configuration makes example.org the default on port 80 and example.net the default on port 8080:

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.
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
server {
    listen 80 default_server;
    listen 8080;
    server_name example.org;
}

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

For a request whose Host header does not match a configured name on a particular endpoint, Nginx uses that endpoint’s default server. The server names documentation covers the per-pair default behavior and provides this pattern.

Test the configuration before applying it

  1. Save the configuration file containing the updated server block.

  2. Run nginx -t. Nginx checks the configuration syntax and attempts to open files referenced by it. The command’s documented behavior is in the command-line switches reference.

  3. If the test succeeds, apply the change using the reload procedure documented for the service manager and installation on your host. There is no single reload command that applies to every installation.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 covers HTTP server blocks. Nginx’s stream and mail modules have their own listen directives and protocol-specific behavior; syntax documented for one module should not be assumed to apply to another. In particular, the stream module documents port-range syntax, which is not evidence that HTTP listen accepts the same form. See the stream listen reference and the Beginner’s Guide.

Optional HTTP listen parameters can also vary by Nginx version. The current HTTP core documentation notes that the http2 listen parameter is deprecated in favor of the http2 directive, and that QUIC support is configured separately. Check documentation for the version installed on your server before adding optional parameters.

If the new port does not respond

  • Check the endpoint: Confirm the intended address and port appear in a listen directive in the relevant HTTP server block.
  • Check which block receives the request: Nginx selects by destination address and port first, then by Host header. Verify the applicable server_name and default server for that endpoint.
  • Check binding and address family: Confirm the configured address is available on the host and that clients can reach it over the intended IPv4 or IPv6 path.
  • Check outside Nginx: Host firewalls, cloud security groups, and public routing affect reachability and depend on the deployment; allow the port where required.
  • Validate after edits: Run nginx -t before applying configuration changes.

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.