Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk11 min

How to Set Up Nginx Server Blocks on a Debian VPS

A practical Debian guide to creating, enabling and testing Nginx server blocks, routing multiple domains, proxying applications and adding Certbot-managed HTTPS.

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.

To host a domain on a Debian VPS, install Nginx, create a document root, save a per-site configuration in /etc/nginx/sites-available/, enable it with a symlink in sites-enabled, validate with nginx -t, and reload Nginx. After DNS and HTTP routing work, use Certbot’s Nginx integration to obtain and install a Let’s Encrypt certificate.

The examples below use example.com. Replace it with your real domain, and confirm the Debian release and package source first: distribution packages and independently maintained upstream packages can use different defaults and versions.

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.

What a server block does

A server block is Nginx’s per-site virtual-server configuration unit. It associates one or more host names with listening ports and a content handler. For a static site, that handler is a directory such as /var/www/example.com. For an application, it can be a reverse proxy that forwards requests to a local service.

When a request arrives, Nginx considers the listening address and port, then compares the request’s Host name with each block’s server_name. Exact names are the normal choice for ordinary domains. Nginx also supports wildcard and regular-expression names, but those should be used only when the routing design requires them. If no matching name exists, Nginx uses the default server for that address and port. That is why requesting a VPS by IP address often shows the distribution’s default page instead of your new site.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Prerequisites and decisions

  • A Debian VPS with administrative access through a root account or sudo.
  • The domain’s DNS A record pointing to the VPS IPv4 address and, if you publish one, its AAAA record pointing to the correct IPv6 address. An incorrect AAAA record can send IPv6 visitors to a different machine even when the A record is correct.
  • Port 80 reachable for initial HTTP testing. Port 443 must also be reachable when you enable HTTPS.
  • A decision about the content model: files served directly by Nginx, or a reverse proxy to an application listening on a local address and port.
  • A record of the Debian release and the package source you intend to use. Package versions, default files and Certbot options change over time, so use repositories supported for that release and avoid mixing unrelated Nginx packages.

Do not begin public certificate issuance until DNS resolves to this VPS and the HTTP server block responds correctly. ACME validation has to reach the names you request.

Install Nginx and inspect the Debian layout

Use the package manager and repository supported by your Debian release. On a standard Debian installation using the distribution package, the usual sequence is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt install nginx
sudo systemctl enable --now nginx
sudo systemctl status nginx

The final command should show an active service. If it does not, read the service output before creating site files; a failed package installation or an existing listener on port 80 has to be corrected first.

Debian-family packaging commonly separates configuration sources from enabled sites:

  • /etc/nginx/sites-available/ stores site files that are available to enable.
  • /etc/nginx/sites-enabled/ contains symlinks for sites Nginx should load.
  • The main configuration includes those enabled files. The exact include statements depend on the package and release.

Use the effective-configuration dump to see what the running binary includes:

sudo nginx -T

Look near the beginning of the output for the main configuration path and included files. This is more reliable than assuming a layout when an independently maintained package is installed.

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

Create a document root for a static site

Choose a separate directory for each domain. The following creates a minimal test page:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
sudo install -d -m 755 /var/www/example.com
sudo tee /var/www/example.com/index.html >/dev/null <<'EOF'
<!doctype html>
<html lang='en'>
<meta charset='utf-8'>
<title>example.com</title>
<h1>Nginx is serving example.com</h1>
EOF

Nginx’s worker process must be able to traverse the directories and read the files. Set ownership and permissions to match your deployment method: a release account may own files and share a read-only group with Nginx, while a simple single-purpose VPS may use the web-service account as owner. Do not use world-writable permissions merely to bypass a permissions error. Check each parent directory as well as the file itself.

Once the test works, replace the placeholder page with your application’s files. Keep the domain-specific root separate from other sites so an incorrect path cannot expose another site’s content.

Write the server block

Create /etc/nginx/sites-available/example.com:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html;
}

Each directive has a distinct job:

  • listen 80; accepts IPv4 HTTP connections on port 80.
  • listen [::]:80; accepts IPv6 HTTP connections. Keep it only when the VPS is configured for IPv6 and the DNS AAAA record points here.
  • server_name lists the host names this block serves. Include every name you intend to publish; a name omitted here can fall through to another block.
  • root maps URL paths to the document directory.
  • index identifies the file Nginx returns for a directory request.

Use exact names for a normal domain. A wildcard can be appropriate for a deliberate subdomain design, while a regular expression should be reserved for a routing rule you have tested carefully. Do not put unrelated domains in one block simply because they currently share files; separate blocks make later TLS, redirects and access rules easier to audit.

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

Enable the site with a Debian-style symlink

Create the enabled-site link, leaving the original file in sites-available for editing and auditing:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

If the packaged default block would otherwise answer requests, remove its enabled link or disable it:

sudo rm /etc/nginx/sites-enabled/default

Only remove the link if you no longer need the default site; the source file in sites-available can remain as a reference. If a file with the same link name already exists, inspect it rather than overwriting it blindly. A stale link pointing to a deleted file will make validation fail.

Validate the complete configuration and reload safely

Always make the syntax test the gate before a reload:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
sudo nginx -t

A successful result reports that the syntax is OK and the test is successful. If it fails, the message identifies a file and line number. Correct that file, run the test again, and do not reload a configuration that has not passed.

When the include hierarchy is unclear, print the fully assembled configuration:

sudo nginx -T

Search that output for example.com, duplicate server_name entries, unexpected default servers and the actual root path. After the test passes, apply the change without dropping existing connections:

sudo systemctl reload nginx

A reload asks the running service to read the new configuration while continuing to serve active workers. A restart is not required for an ordinary server-block edit and introduces a larger interruption risk.

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

Test host routing before adding TLS

Test with the real names, not only the VPS address:

curl -i http://example.com/
curl -i http://www.example.com/

Check that DNS resolves both names to the intended VPS and that the response body is the test page from the correct root. If DNS has not propagated, send an explicit Host header to the VPS address:

curl -i -H 'Host: example.com' http://203.0.113.10/

Replace the example address with the VPS’s actual IPv4 address. This test exercises Nginx host matching without waiting for public DNS, but it does not prove that external resolvers or IPv6 clients will reach the server.

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.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

A request made directly to an IP address has no matching domain name, so Nginx may select the default server. That behavior is expected and is not evidence that the named block is broken.

Static files versus a reverse proxy

The server-block selection process is the same for both models; only the content handler changes.

Deployment choice Server-block pattern Best fit Important checks
Static files root /var/www/example.com; and an index file HTML, CSS, JavaScript and other files that Nginx can read directly Directory traversal permissions, correct root path and the presence of the requested file
Reverse proxy A location / using proxy_pass to a local application Web applications that generate responses or manage their own routing The application must be listening on the configured address and port; proxy headers and the application’s logs must agree with the public host and scheme

A minimal reverse-proxy block can be added in place of the static directives. Replace port 3000 with the port your application actually uses:

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

    location / {
        proxy_pass http://127.0.0.1:3000;
        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;
    }
}

Do not keep a misleading root and index configuration in a block that is intended solely as a proxy. After changing the block, run the same test-and-reload sequence, then request the domain and verify that the application—not the default page—produces the response.

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

One domain, several names, or several sites

Putting example.com and www.example.com in one server_name line is appropriate when both names should serve the same content. If one name should redirect to the other, use a separate block for the redirect so the canonical-name policy is explicit. If two domains have different roots or applications, give each its own file and symlink.

Requirement Configuration approach What to verify
One site under two names List both exact names in one server_name directive Both DNS names resolve to this VPS and the content policy is identical
Separate sites on one VPS Use one server-block file and document root per domain No duplicate or overlapping names cause an unintended block to win
Wildcard subdomains Use an intentional wildcard name and a matching certificate strategy The wildcard does not capture names that need different applications or policies
IP-address testing Use an explicit Host header or a real DNS name The request is testing host matching rather than the default server
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add HTTPS with Certbot and Let’s Encrypt

Once port 80, DNS and the HTTP block work, install Certbot and its Nginx integration from a package source supported by your Debian release. Then request the names that the site serves:

sudo certbot --nginx -d example.com -d www.example.com

Certbot’s documented Nginx plugin can authenticate the names and install certificates. Review the changes it makes to the server blocks instead of treating generated configuration as opaque. It may add a TLS listener, certificate directives and an HTTP-to-HTTPS redirect according to the choices you make.

Certificate material managed by Certbot is documented under /etc/letsencrypt/live/. Protect that directory and avoid editing generated certificate files directly. The names on the certificate must match the names visitors use; obtaining a certificate for only example.com does not cover www.example.com.

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

Keep the network path required by the selected ACME challenge available. Port 80 is commonly needed for HTTP validation, and port 443 must be reachable for normal HTTPS service. After installation, test both schemes:

curl -I http://example.com/
curl -I https://example.com/

Test renewal using the renewal command supported by your Certbot installation. A successful dry run is evidence that the scheduled renewal path can authenticate and reload the service; it is not a substitute for checking the certificate’s names and expiration in your monitoring.

Comparison of the main packaging and protocol choices

Choice Advantages Trade-offs and qualifications
Debian-packaged Nginx Integrated with the release’s package management and service layout, including the common sites-available/sites-enabled convention Version and defaults follow the Debian release; confirm them before applying instructions written for another release
Independently maintained upstream package May provide a different or newer Nginx build Paths, included files, service behavior and update policy can differ; use that package’s documented layout rather than assuming Debian defaults
HTTP only Simplest initial routing test Traffic is not encrypted; treat it as a setup phase, not the finished public configuration
HTTP plus HTTPS Encrypted connections on port 443 with a certificate for the published names Requires working DNS, reachable validation paths, certificate renewal and a reviewed TLS configuration
Static serving Fewer moving parts and no application listener to maintain All requested files must exist under the root and be readable by Nginx
Reverse proxying Supports application servers and dynamic routing behind Nginx The upstream process, local port, proxy headers and application error handling all become part of the request path

Troubleshoot the common failure modes

Nginx still serves the default page

  • Confirm the request uses the intended domain or an explicit Host header; an IP-only request can select the default server.
  • Check that the symlink exists in /etc/nginx/sites-enabled/ and points to the expected file in sites-available.
  • Inspect nginx -T for another block that claims the same name or is marked as the default for the same listener.
  • Verify both DNS record types. An outdated AAAA record can make only IPv6 clients reach the wrong server.

The configuration test reports an error

Read the filename and line number in the nginx -t output. Typical causes include a missing semicolon, an unmatched brace, a misspelled directive, a broken symlink or a directive available in one package version but not another. Fix the named file and rerun the test; do not use a reload to discover syntax errors in production.

The site returns 404

For a static block, compare the requested URL with the resolved path under root, check the spelling and case of the file, and confirm that the index file exists. A permissions problem can appear in the error log even when the path looks correct. For a proxy block, a 404 may come from the application itself, so compare the Nginx access log with the application log.

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

The site returns 403

Check traversal permission on every parent directory and read permission on the requested file. Directory requests without an available index may also be denied according to the active configuration. Correct ownership or group permissions deliberately rather than making the entire tree writable.

The proxy returns 502 Bad Gateway

Confirm that the application is running and listening on the exact address and port in proxy_pass. A service bound only to a different address, a stopped process or a local firewall rule can prevent Nginx from connecting. The Nginx error log identifies connection-refused and timeout conditions.

Certbot cannot validate the domain

  • Resolve the domain from outside the VPS and verify that every requested name reaches this server.
  • Make sure port 80 is reachable when the selected challenge requires it and that the HTTP block is enabled.
  • Check that the request is not being sent to a default block, redirect loop or unrelated IPv6 host.
  • Read Certbot’s error output, correct DNS or routing, and rerun the request rather than repeatedly requesting certificates for a name that still resolves incorrectly.

Find evidence in the logs

When the response is unexpected, correlate the request with Nginx’s access and error logs, commonly under /var/log/nginx/. The access log confirms which requests reached this machine; the error log explains file, permission, upstream and TLS failures. Combine those entries with the resolved DNS address, the request’s host name, the listening port, the configured root and the filesystem permissions.

Final deployment checklist

  1. Record the Debian release and confirm the Nginx package source.
  2. Point the domain’s A and, when applicable, AAAA records to the VPS.
  3. Install Nginx and confirm the service is active.
  4. Create a dedicated document root or define the application’s local upstream.
  5. Save the block in sites-available with exact server_name values.
  6. Enable it with a symlink in sites-enabled and disable an interfering default link.
  7. Run nginx -t; use nginx -T when you need to inspect the assembled configuration.
  8. Reload Nginx only after the syntax test passes.
  9. Test each published name with DNS and, if necessary, an explicit Host header.
  10. Install Certbot’s Nginx integration, request certificates for all required names, review the generated TLS settings and test renewal.

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 *

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
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.