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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Yes—one Nginx server can host many domains and subdomains, including multiple HTTPS sites on a single IP. Put each site in a server block inside the http context, list its hostnames with server_name, point DNS records at the server, install certificates for every HTTPS name, then test the complete configuration before reloading Nginx.

The examples below use two sites: a static site at example.com (also available as www.example.com) and an application at app.example.com proxied to port 3000. Replace those names, paths, and upstreams with your own values.

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.

How Nginx chooses the site for a request

Nginx can load multiple virtual servers in the http context. Every server block declares one or more listening addresses and ports, then identifies the hostnames it should answer with server_name. Nginx compares the hostname supplied by the client with those names and selects the matching block. The selected block can have its own document root, URL locations, proxy upstream, access rules, logging, and TLS certificate.

For HTTP, the hostname arrives in the request’s Host header. For HTTPS, Nginx may need the hostname during the TLS handshake through Server Name Indication (SNI) so it can present the right certificate; it then uses the HTTP hostname to select request handling. A certificate mismatch can therefore occur before a location rule is evaluated.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

Use one logical block per application or site whenever the roots, upstreams, security policy, or ownership differ. A single block may list aliases that intentionally serve the same content.

Plan the names, DNS records, and files first

Choose a block layout

You can place all blocks in one configuration file, or use the distribution convention of sites-available and sites-enabled symbolic links. The layout is not what makes virtual hosting work: every file must ultimately be included inside Nginx’s http context. Check the main configuration’s include directives if a new file appears to be ignored.

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

Give each block a unique, intentional set of names. Duplicate names on the same address and port make selection dependent on ordering and can produce warnings or an unexpected site. Keep production names explicit unless a wildcard is genuinely required.

Create DNS records before troubleshooting Nginx

For each public hostname, create an A record pointing to the server’s IPv4 address. Create an AAAA record only when IPv6 is correctly routed to the host and Nginx listens on IPv6. Point the apex and aliases deliberately; a wildcard record does not automatically cover the apex.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
  • example.com — an A record to the server (and an AAAA record only for working IPv6).
  • www.example.com — an explicit record, often an A/AAAA record or a DNS alias where your provider supports it.
  • app.example.com — a record to the same server when the application is hosted there.

Use a DNS wildcard only when every matching subdomain should reach the same Nginx entry point. Confirm public resolution with your DNS tools before investigating server blocks; a name that resolves elsewhere cannot be routed by this Nginx instance.

Configure separate HTTP server blocks

This is a minimal arrangement for a static site and a reverse-proxied application:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    root /srv/www/example;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;

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

Static site block

server_name example.com www.example.com makes both names use the same files under /srv/www/example. The try_files rule serves an existing file or directory and returns a 404 response when neither exists. Ensure the Nginx worker user can traverse the directory and read the files.

Reverse-proxy block

The application block has no local root; requests are sent to a process listening on 127.0.0.1:3000. The forwarded headers preserve the public hostname, client address chain, and original scheme so the application can build correct links and enforce HTTPS-aware behavior. Change the upstream address if the service runs on another host or port.

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

When to add another block

Create a separate block when a hostname needs a different document root, upstream service, authentication policy, rate limit, logging policy, or certificate grouping. Keep aliases in one block only when they should remain operationally identical.

Exact names, aliases, and wildcards

Nginx accepts exact names, wildcard names, and regular-expression names. Exact names are easiest to audit and safest for unrelated production applications.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Pattern Matches Does not match Typical use
example.com Only the apex name www.example.com or any subdomain A site that should answer only on its canonical name
example.com www.example.com Both listed names Unlisted subdomains One site with an apex and a www alias
*.example.com One subdomain level, such as app.example.com example.com and api.eu.example.com Many first-level tenants using the same handling
~^(.+).example.com$ Names matching the regular expression Anything outside that expression Advanced dynamic naming, with extra review required

A wildcard such as *.example.com does not include the apex and does not extend to deeper labels. If you need both the apex and first-level subdomains, list the apex explicitly alongside the wildcard in the relevant configuration and certificate. A deeper name such as api.eu.example.com needs its own exact or appropriately designed pattern.

Serve several HTTPS domains on one IP

Each HTTPS block needs an SSL listener, a certificate, and the matching private key:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com www.example.com;

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

    root /srv/www/example;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name app.example.com;

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

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

SNI allows several HTTPS names to share one IP: the client sends the requested hostname during TLS negotiation, and Nginx selects a certificate whose names cover it. The certificate must contain the exact hostname or a matching wildcard. A wildcard certificate for *.example.com covers one subdomain level, not example.com or a deeper name. Include all required names as certificate subject-alternative names (SANs), or use separate certificates.

Per-host certificates versus SAN or wildcard certificates

Approach Strengths Trade-offs
One certificate per hostname Small coverage scope and independent renewal or replacement More certificate files and renewal jobs to track
One SAN certificate for several known names Fewer certificate objects to configure and renew Adding or removing a name requires reissuing the shared certificate; one key’s exposure affects every included name
Wildcard certificate Convenient for many first-level subdomains Does not cover the apex or deeper labels; the wildcard private key has a broad blast radius

Protect private keys so only Nginx and the account responsible for certificate management can read them. Do not make key files world-readable, and avoid granting unrelated service users access.

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.

Choose a deliberate default HTTPS server

If no server_name matches, Nginx uses the default server for that address and port. Configure that default intentionally—for example, return a simple 444/404-style response or a controlled error page—rather than accidentally exposing the first site’s content. This also makes scans and mistyped hostnames easier to interpret.

Redirect HTTP to HTTPS safely

After every intended hostname has a working certificate, use a dedicated port-80 redirect block:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com app.example.com;
    return 301 https://$host$request_uri;
}

$host preserves the requested hostname and $request_uri preserves the path and query string. Do not enable this redirect before certificate issuance is complete if an ACME client still needs HTTP-01 validation. Keep the challenge location available, or use the exception generated by your certificate client.

With DNS-01 validation, the automation must be able to create the required TXT records at your DNS provider. The exact commands and permissions depend on the ACME client and DNS provider; test renewal rather than assuming initial issuance proves automation will continue to work.

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

Automate certificates without breaking name coverage

Certificate identifiers should correspond to the hostnames in your server_name directives. For every block, verify that the certificate chain path and private-key path exist, are readable by Nginx, and are updated by your renewal process. If a certificate combines an apex and wildcard, confirm both names are present in its SAN list—the wildcard alone is insufficient for the apex.

When adding a hostname, update DNS, the Nginx block, and certificate automation as one change. Renew or reissue the certificate before sending users to the new HTTPS name, then test both the old and new names if aliases were changed.

Compare one shared block with separate blocks

Decision factor Shared block with several names Separate blocks
Isolation All names share roots, locations, headers, and most policy Each application can have independent rules and upstreams
Certificate grouping Convenient for aliases or a deliberately shared SAN certificate Certificates can be renewed or replaced per application
Deployment ownership One team and release process for all names Different teams can change their own site’s configuration
Troubleshooting Fewer blocks, but a change can affect every alias Clearer mapping from hostname to behavior, with more files to inspect
Best fit Canonical name plus aliases serving identical content Different roots, services, access controls, or operational lifecycles

There is no requirement that every subdomain have its own block. The correct boundary is a change in behavior or ownership, not the mere existence of another DNS name.

Validate and reload the complete configuration

  1. Check the assembled configuration: run nginx -t. This validates syntax and referenced files in the complete loaded configuration, not just the file you edited.
  2. Fix every reported error: common causes include a missing semicolon, an unreadable certificate key, an invalid include path, duplicate or malformed directives, and a certificate file that was moved during renewal.
  3. Reload through the operating system’s service manager: use the reload operation for your host, such as systemctl reload nginx. A reload lets existing workers finish while new workers use the validated configuration.
  4. Confirm DNS: query each name and verify that its A and, when used, AAAA records resolve to the intended server.
  5. Test by hostname, not only by IP: request both HTTP and HTTPS URLs with each name. Testing an IP alone can select the default server and bypass the virtual-host decision you need to verify.
  6. Inspect TLS and response details: check the certificate subject/SANs, issuer, expiry, status code, and response headers for every hostname. Use your browser’s certificate viewer or command-line TLS/HTTP clients.

For a private or not-yet-public DNS name, you can test routing with a temporary hosts-file entry or an HTTP client’s host-resolution option, while still connecting to the server’s real address. Remove the temporary override after testing so it does not hide DNS mistakes.

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

Troubleshoot the wrong site or a failed certificate

The wrong content appears

  • Check for duplicate server_name values on the same port and address.
  • Confirm the request uses the intended hostname and that the DNS record points to this server.
  • Inspect which block is the default for the listener; an unmatched name will land there.
  • Verify that both the port-80 and port-443 listeners have the expected names. An HTTP block does not automatically configure HTTPS.
  • Check reverse-proxy logs and confirm the application receives the expected Host header.

HTTPS fails while HTTP works

  • Make sure the block listens with listen 443 ssl and has valid ssl_certificate and ssl_certificate_key paths.
  • Confirm the certificate covers the exact hostname or its one-level wildcard equivalent.
  • Check private-key permissions and the Nginx error log for permission or parsing errors.
  • Test IPv4 and IPv6 separately. A stale or misrouted AAAA record can send clients to a host that is not configured for the site.
  • Remember that SNI and certificate selection happen before normal HTTP locations; a valid proxy or static-file rule cannot repair a certificate that does not cover the requested name.

Certificate issuance or renewal fails

  • Verify the name resolves publicly to the validation endpoint.
  • For HTTP-01, ensure port 80 is reachable and the ACME challenge path is not swallowed by an unconditional redirect or another location.
  • For DNS-01, verify that automation can create and later remove the required TXT records.
  • After renewal, run nginx -t and reload so workers use the new certificate.

Production checklist

  • Every hostname has an intentional DNS record and, if applicable, a correctly routed IPv6 record.
  • Each site or application has a clear server-block boundary and no accidental duplicate names.
  • HTTP blocks listen on both IPv4 and IPv6 only when the host is configured for both.
  • HTTPS blocks include the right certificate chain, private key, and hostname coverage.
  • Wildcard names and certificates are used only for the intended one-level scope; the apex and deeper names are handled explicitly.
  • Private keys are protected from unnecessary users.
  • ACME challenge handling and renewal permissions are tested.
  • nginx -t passes before every reload.
  • Each hostname is tested over HTTP and HTTPS, including certificate details and the final upstream or static response.
  • The unmatched-name default server returns a deliberate response rather than an unintended site’s content.

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.