Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchYes—you can host many HTTP and HTTPS websites on one NGINX server and one IP address. Create port-80 virtual hosts for each hostname, create matching TLS virtual hosts that listen on port 443, and give each TLS block a certificate covering its server_name. SNI puts the requested hostname in the TLS handshake so NGINX can select the right certificate and site. If every site must be secure, make each port-80 block return 301 https://$host$request_uri.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The configuration below uses two domains, but the same pattern scales to additional names. Replace the example hostnames, certificate paths, document roots, and upstream addresses with values from your deployment, then run nginx -t before reloading NGINX.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →How SNI lets several HTTPS sites share one IP
In a traditional HTTPS connection, the server needs to know which certificate to present during the TLS handshake. When several domains share one address, the client supplies the requested hostname through Server Name Indication (SNI), an extension defined by RFC 6066. NGINX reads that name early in the handshake and chooses the matching server block and certificate. After TLS is established, normal HTTP request processing uses the request line and, where applicable, the Host header to select the content configuration.
This is why one address can serve site-one.example and site-two.example without a separate IP for each. The client must support SNI, DNS for every name must resolve to the NGINX address, and each certificate must cover every name that clients use. A client that does not send SNI cannot identify the intended site at handshake time; it receives the certificate from the default TLS server instead.
#1 Best Overall
Prerequisites to check before editing NGINX
- DNS: Create address records for every hostname and make sure they resolve to the server’s public address. Include both the bare name and
wwwonly if you intend to serve both. - Reachable ports: Permit TCP 80 and TCP 443 through the host firewall, cloud security group, load balancer, and any upstream network device that sits in front of NGINX.
- NGINX SSL support: The build must include the HTTP SSL module. The TLS virtual hosts require
listen 443 ssl,ssl_certificate, andssl_certificate_key. - Certificates: Obtain a certificate and private key for each hostname set, or choose a certificate that deliberately covers several names. The certificate’s names must match every value in the corresponding
server_namedirective. - Content or an upstream: Decide whether NGINX will serve files directly from a
rootdirectory or proxy requests to an application server. - Key protection: Restrict private-key permissions so that only the NGINX master process and the administrators who manage certificates can read them.
The paths in examples such as /etc/letsencrypt/live/site-one.example/fullchain.pem are illustrative. They are not proof that a particular certificate automation method or directory layout is present on your system.
Choose a server-block layout
There are two sound ways to express the HTTP/HTTPS relationship. Separate blocks make the redirect behavior obvious and let the HTTP and HTTPS sites evolve independently. A single block can listen on both ports when the same virtual host should handle both protocols; NGINX documents this as placing one listen directive without SSL and one with the ssl parameter in the same server.
| Design | Best fit | What to watch |
|---|---|---|
| Separate port-80 redirect and port-443 content blocks | Sites that should force HTTPS, or deployments where cleartext and TLS have different behavior | Keep the hostname lists and redirect policy synchronized |
| One block listening on 80 and 443 | A virtual host that intentionally serves content over both protocols | Do not assume HTTPS is enforced; add an explicit redirect block if security policy requires it |
| Shared IP with SNI | Modern browsers and clients that send SNI | Non-SNI clients use the default certificate and cannot reliably select a name-specific TLS site |
| Separate IP addresses | Legacy clients that cannot use SNI or environments requiring address-level isolation | Uses more addresses and does not provide the simplicity of shared-IP hosting |
Recommended configuration: redirect HTTP and serve two HTTPS sites
This pattern gives each hostname a clear port-80 redirect and a separate TLS block. It preserves the original host and URI: $host supplies the requested hostname and $request_uri includes the path and query string.
Rank #2
# HTTP to HTTPS redirect for site one
server {
listen 80;
server_name site-one.example www.site-one.example;
return 301 https://$host$request_uri;
}
# HTTPS site one
server {
listen 443 ssl;
server_name site-one.example www.site-one.example;
ssl_certificate /etc/letsencrypt/live/site-one.example/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site-one.example/privkey.pem;
root /var/www/site-one;
index index.html;
}
# HTTP to HTTPS redirect for site two
server {
listen 80;
server_name site-two.example www.site-two.example;
return 301 https://$host$request_uri;
}
# HTTPS site two
server {
listen 443 ssl;
server_name site-two.example www.site-two.example;
ssl_certificate /etc/letsencrypt/live/site-two.example/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site-two.example/privkey.pem;
root /var/www/site-two;
index index.html;
}
Place these blocks in the configuration location used by your NGINX installation, such as an included virtual-hosts file. Replace every example value before enabling it. The two port-443 blocks may share the same IP because SNI distinguishes their names during the handshake.
What each directive does
listen 80;accepts cleartext HTTP on the conventional port.listen 443 ssl;accepts TLS connections and enables SSL handling for that listener.server_namelists the names that map to the block. If users can enter both the bare andwwwforms, list both and cover both in the certificate.ssl_certificatepoints to the certificate chain presented to clients.ssl_certificate_keypoints to the corresponding private key. The key must match the certificate.rootselects the directory from which static files are resolved, andindexidentifies the default file.return 301ends the port-80 request immediately with a permanent redirect instead of serving duplicate cleartext content.
Serving static files or proxying an application
The certificate and SNI portion is the same whether the HTTPS block serves files or forwards requests. For a static site, keep the root and index directives in the TLS block. For an application, replace or supplement them with a location that proxies to the appropriate upstream.
Static site per hostname
server {
listen 443 ssl;
server_name site-one.example www.site-one.example;
ssl_certificate /path/to/site-one/fullchain.pem;
ssl_certificate_key /path/to/site-one/privkey.pem;
root /var/www/site-one;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
The try_files choice shown here returns a 404 when neither a file nor a directory exists. A single-page application may need a different fallback, while a conventional file tree may not need a custom location at all; choose behavior that matches the application rather than copying this line blindly.
Recommended Free Tools
Reverse proxy per hostname
server {
listen 443 ssl;
server_name site-two.example www.site-two.example;
ssl_certificate /path/to/site-two/fullchain.pem;
ssl_certificate_key /path/to/site-two/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
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;
}
}
Use a distinct upstream address or port for each application when they run on the same machine. The TLS certificate still belongs in the NGINX block; the application can remain HTTP on its loopback interface if that is the intended trust boundary.
One combined block for both protocols
If a hostname is deliberately available over both HTTP and HTTPS, NGINX can attach both listeners to one block:
server {
listen 80;
listen 443 ssl;
server_name site-one.example www.site-one.example;
ssl_certificate /path/to/site-one/fullchain.pem;
ssl_certificate_key /path/to/site-one/privkey.pem;
root /var/www/site-one;
index index.html;
}
This arrangement is not an HTTP-to-HTTPS redirect. Requests arriving on port 80 are handled by the same content configuration. Use the separate redirect-and-content pattern when cleartext must never return the site, when cookies or credentials require TLS, or when policy requires every URL to be canonicalized to HTTPS.
Rank #4
Certificate choices for multiple names
SNI selects a server block, but the certificate presented by that block still has to cover the hostname. You can represent the names in several ways:
| Certificate approach | How it maps to NGINX | Operational trade-off |
|---|---|---|
| One certificate per hostname or hostname set | Each TLS block points to its own ssl_certificate and ssl_certificate_key |
Isolation is clear, but each certificate has its own issuance, renewal, and key files |
| Subject Alternative Name (SAN) certificate | Several names can use the same certificate paths when the certificate lists them all | Fewer certificates to renew, but replacing one name may require replacing the shared certificate and key |
| Wildcard certificate | A wildcard name can cover matching subdomains according to certificate-name rules | Convenient for a subdomain family, but it does not automatically cover the apex domain or unrelated names |
Do not infer coverage from a filename. Inspect the certificate’s names and ensure every value in server_name is covered. If the certificate and private key do not form a pair, NGINX will reject the configuration or the TLS handshake will fail.
Deployment procedure
- Inventory names and destinations. Write down every public hostname, whether its HTTP form should redirect, its document root or upstream, and the certificate and key paths that will serve it.
- Publish DNS. Point each name to the address that reaches this NGINX instance. Wait for the records to resolve from the networks your users will use before interpreting certificate or routing errors.
- Create content or upstreams. Make
/var/www/site-oneand the other roots readable by the NGINX worker process, or start the applications that NGINX will proxy to. Verify each destination locally before adding TLS complexity. - Install certificate files securely. Put the full certificate chain and matching private key at the paths in the TLS blocks. Keep the private key readable only by the NGINX master process and authorized administrators.
- Add one port-80 block per hostname set. Use the exact names that DNS and the certificate cover. Return a 301 redirect when the site is HTTPS-only.
- Add one port-443 block per TLS selection. Set
listen 443 ssl, the matchingserver_name, both certificate directives, and either static-file or proxying directives. - Define unmatched-host behavior. Decide which server should be the intentional default for port 80 and port 443. A default can return a controlled error or a neutral response instead of exposing the first site’s content.
- Validate before applying. Run
nginx -t. Fix every syntax error, missing file, permission error, duplicate conflict, or certificate/key mismatch it reports. - Reload gracefully. Use your operating system’s NGINX service reload mechanism after the test succeeds. A reload lets existing connections finish while workers adopt the new configuration; use the service manager command appropriate to your installation.
- Test both protocols and every name. Request each HTTP hostname and confirm the Location header points to the same host over HTTPS. Then connect to each HTTPS hostname and verify the certificate name, response content, redirects, and application routing.
How NGINX chooses a block, in order
Port 80
NGINX first groups listeners by address and port, then compares the HTTP request’s host information with server_name. The matching port-80 block returns the redirect or serves cleartext content. If no name matches, the listener’s default server handles the request, which is why an explicit default is preferable to accidental first-file behavior.
Port 443
For TLS, the SNI name arrives during the handshake. NGINX uses it to choose the certificate and TLS server block before the encrypted HTTP request is available. Once the handshake succeeds, request processing can use the HTTP host value to select the appropriate configuration. A wrong certificate therefore points first to SNI, certificate coverage, or default-server selection—not to the document root.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Default servers and unmatched hostnames
Shared-IP hosting needs a deliberate response for names you did not configure. Without one, NGINX may answer with whichever server is the default for that address and port. That can expose the wrong site’s certificate or content and makes troubleshooting difficult.
# Intentional HTTP default
server {
listen 80 default_server;
server_name _;
return 444;
}
# Intentional HTTPS default
server {
listen 443 ssl default_server;
server_name _;
ssl_certificate /path/to/default/fullchain.pem;
ssl_certificate_key /path/to/default/privkey.pem;
return 444;
}
The example uses a deliberately controlled response for unknown hosts. Select a response that fits your monitoring and security policy. A TLS default still needs a certificate because the handshake occurs before NGINX can return an HTTP response; non-SNI clients will see this default certificate.
Non-SNI clients and when one IP is not enough
Modern browsers generally send SNI, but an old client, embedded device, or specialized TLS library may not. A non-SNI client cannot tell NGINX which certificate it wants, so the default TLS block supplies the certificate. If that certificate does not contain the requested hostname, the client reports a name mismatch even though a matching server block exists.
There are two documented ways to accommodate such clients: assign separate IP addresses so the address itself selects the site, or use one multi-name certificate that covers the names those clients need. Separate addresses consume more network resources; a shared certificate couples the names operationally. Choose based on the clients you actually must support rather than disabling SNI-based separation.
Quick Recap
Validation and troubleshooting
| Symptom | Likely cause | Checks and correction |
|---|---|---|
| HTTP request reaches the wrong site | DNS points elsewhere, the hostname is absent from server_name, or an unintended default server is answering |
Confirm DNS resolution, inspect all port-80 blocks, and create an explicit default response for unknown names |
| HTTP does not redirect | The request matches a content-serving port-80 block or the redirect block is not loaded | Ensure the name appears in the redirect block, remove unintended port-80 content handling, run nginx -t, and reload |
| HTTPS shows another site’s certificate | The client omitted SNI, the name does not match the intended block, or the TLS default is being selected | Test with an SNI-capable client, verify the exact hostname spelling, inspect the 443 server_name list, and check which block is default |
| Certificate-name mismatch | The certificate does not include the requested bare or www name |
Issue or install a certificate covering every public name and point the block to its matching chain and key |
| NGINX test reports a missing certificate file | The configured path is an example, a symlink target is absent, or permissions prevent access | Check the path and symlink target, then grant the NGINX master process read access without making the key world-readable |
| NGINX test reports a key mismatch | The private key belongs to a different certificate | Replace one file with the matching pair; do not solve the problem by pointing several sites at unrelated keys |
| HTTPS returns the right certificate but wrong content | The TLS name selected correctly, but request routing, duplicate names, or root/upstream settings are wrong | Search loaded configuration for duplicate server_name entries, then verify the selected block’s root or proxy_pass |
| Application works directly but fails through HTTPS | The upstream is down, the proxy address is wrong, or forwarded headers are missing | Test the upstream locally, confirm its port, and pass the original host and scheme when the application needs them |
| Configuration changes have no effect | The edited file is not included, validation failed, or NGINX was not reloaded | Check the include structure, run nginx -t, reload only after a successful test, and inspect the active service configuration |
Security and maintenance considerations
- Keep the redirect policy consistent. If a site is intended to be HTTPS-only, give every cleartext hostname a redirect block, including alternate names you publish.
- Renew before expiry. When a certificate is replaced, update the chain and key paths atomically where your deployment method permits, run
nginx -t, and reload only after validation. - Review protocol settings against your NGINX version. TLS protocol defaults and directive behavior can change; use the current NGINX SSL-module reference for version-specific settings instead of copying an old hardening snippet.
- Limit key exposure. Certificate chains are public, private keys are not. Keep backups protected and ensure logs, configuration archives, and deployment artifacts do not disclose keys.
- Separate names intentionally. Do not place unrelated domains in one
server_namelist merely to reduce file count. Group names only when they share certificate coverage, content, redirect policy, and lifecycle. - Monitor each hostname. A shared listener can remain healthy while one certificate expires or one upstream stops responding. Check every public name, not just the server address.
Practical design checklist
- Every hostname resolves to the NGINX address.
- Every public name appears in exactly the intended port-80 and port-443
server_namelists. - Every TLS block has
listen 443 ssl, a certificate, and its matching private key. - Certificate names cover both apex and
wwwforms when both are published. - Port 80 either redirects deliberately or serves content deliberately; it is not accidental.
- Static roots and upstream destinations are different for sites that must remain isolated.
- An explicit default server handles unknown and non-SNI traffic.
- Private keys are readable only by the NGINX master process and authorized operators.
nginx -tsucceeds before every reload.- Tests cover redirects, certificate identity, content, error handling, and application paths for every hostname.
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

