To serve a static HTML site, put the files in a readable document root and add an Nginx server block that sets the listening port, hostname, root, index, and a try_files rule. This working baseline serves /data/www/index.html, returns other existing files such as about.html, and sends a 404 response for paths that do not exist:
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
server {
listen 80;
server_name example.com www.example.com;
root /data/www;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
What Nginx must decide for each request
Serving a static page is a sequence of configuration decisions rather than a special HTML mode. Nginx receives a request, chooses a virtual server, chooses the best matching location, maps the URI to a filesystem path, and then either returns the file or applies the configured fallback.
As an Amazon Associate I earn from qualifying purchases.
1. The listening socket and hostname select the server block
The listen directive identifies the address and port handled by a server block. Nginx then compares the request’s Host header with server_name. Names can be exact names, wildcard names, or regular-expression names. If several blocks listen on the same address and port, the name match determines which one handles the request; a request that does not match the name you intended can therefore be served by another, often packaged default, configuration.
2. The location determines request handling
A location block matches part of the request URI and supplies directives for that match. A simple site normally uses location /, which covers every URI not handled by a more specific location. More specific locations are useful for an image directory, a custom error page, or a file pattern that needs different cache headers.
#1 Best Overall
- [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.
3. The root turns a URI into a filename
With root /data/www;, Nginx appends the request URI to /data/www. A request for /about.html therefore maps to /data/www/about.html. The same rule applies beneath a location unless another root or an alias is active. The directory must exist on the server where the worker processes run; a path that exists on your development computer is irrelevant unless it also exists at that exact server path.
4. Index processing handles a directory request
When the client requests /, the index directive supplies filenames to check. Nginx documents index.html as the default, and you can list several names in order. If an index file is found, Nginx internally redirects to that file URI and processes the new URI through location selection again. This is why a request for / can ultimately be logged and handled as /index.html.
Recommended Free Tools
Prepare the document root and files
Choose a directory that will contain only the site content you intend to publish. The official beginner configuration uses /data/www; you can use another absolute path if the path in the configuration and the path on disk are identical.
- Create the document-root directory using the operating system’s normal file-management tools.
- Place an
index.htmlfile directly inside it. Add files such asabout.htmland an asset directory such asimagesbeneath it. - Confirm that the Nginx worker processes can traverse every parent directory and read the files. Ownership and permission requirements differ by operating system and package, so check the local service account and the permissions on each directory in the path.
- Keep the filenames and URL spelling consistent. Linux filesystems are commonly case-sensitive:
/About.htmland/about.htmlmay be different files.
A minimal test page makes failures easy to recognize:
<!doctype html>
<html lang='en'>
<head><meta charset='utf-8'><title>Test page</title></head>
<body><h1>Nginx is serving this file</h1></body>
</html>
Build the minimal static-site server block
Put the following block inside the configuration’s http context. A server block placed outside http is invalid, even if every directive inside it is spelled correctly.
server {
listen 80;
server_name example.com www.example.com;
root /data/www;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
listen 80;
This example accepts HTTP traffic on port 80. If your service listens on another address or port, the value must match the address clients use and the port exposed by the host or network device.
Outdated 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 matchWindows 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 reinstallRank #2
- 【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.
server_name example.com www.example.com;
List every hostname that should use this site. An exact name is the narrowest choice. Wildcards can cover a family of names, while regular expressions are available for more complex matching; use them only when you understand which request names they will capture. A missing or misspelled name can send a request to a different server block.
root /data/www;
root defines the filesystem directory used to construct local filenames. It does not move files and it does not remove the URI prefix. For example, /images/logo.svg becomes /data/www/images/logo.svg with this root.
index index.html;
This explicitly declares the default document. You may provide an ordered list, such as index index.html home.html;; Nginx checks the names in that order when a directory URI is requested. Keep the file in the directory produced by the root mapping.
location / { ... }
The slash location is the general static-content handler. It is a good place for try_files because it gives ordinary files and directories a predictable result while allowing more specific locations to be added later.
try_files $uri $uri/ =404;
try_files checks candidates in order. $uri tests the requested path as a file, $uri/ tests it as a directory, and =404 returns an explicit 404 status if neither exists. Each candidate is constructed from the active root or alias. This prevents a nonexistent URL from being silently treated as a successful file request.
How a request is resolved
Understanding the sequence makes configuration errors much easier to diagnose.
Rank #3
- [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
- Nginx accepts the connection on the address and port selected by
listen. - It compares the hostname with the available
server_namevalues and selects a virtual server. - It evaluates the request URI against the
locationdirectives and chooses the applicable block. - It combines the URI with the active
rootor applies the location’saliasmapping to produce a filesystem path. - If the URI names a directory, the
indexlist is checked. Findingindex.htmlcauses an internal redirect to that file URI, which goes through location selection again. - If
try_filesis present, its candidates are tested in order. The first existing file or directory is used; otherwise the final URI or status code is applied.
For the baseline block, / normally resolves to /data/www/index.html, /about.html resolves to /data/www/about.html, and a missing path such as /does-not-exist receives a 404.
Useful layout variations
Serve an asset directory from a separate parent
The beginner configuration demonstrates a separate location for images:
location /images/ {
root /data;
}
With this mapping, /images/logo.png is looked up as /data/images/logo.png. Notice that the root is /data, not /data/images; Nginx appends the complete URI beneath the configured root. Use this pattern when an asset tree has a different common parent from the main document root.
Use alias when the location itself should be replaced
root appends the complete URI, whereas alias maps a matching location to a different filesystem path. The distinction matters when the URL prefix should not appear in the on-disk path. Test an alias with a known file before deploying it, because a prefix or trailing-slash mistake can produce unexpected filenames. Keep the mapping in the most specific location that needs it.
Return a custom not-found page
If a branded error document is required, replace the final =404 action with a URI and define a location that serves the corresponding file. The important parts are that the fallback file really exists under the active root and that the custom location does not create a loop back into the same failing request. The official example configuration uses a dedicated /404.html location for this purpose.
location / {
try_files $uri $uri/ /404.html;
}
location = /404.html {
root /data/www;
}
Use the direct =404 form when a plain status is preferable; use a fallback URI only when you have created and tested that page.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Rank #4
- 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.
Check additional candidates before failing
Some sites want a directory index or an extensionless page to resolve in a defined order. Nginx’s rewrite documentation illustrates ordered checks such as $uri, $uri/index.html, and $uri.html. A corresponding rule could be:
location / {
try_files $uri $uri/index.html $uri.html =404;
}
Only add candidates that reflect files you actually maintain. Every extra fallback changes which URL wins when more than one file exists.
Add cache behavior for static assets
Static CSS, JavaScript, image, and font files can use a more specific location with cache headers, while HTML can remain easier to refresh. The official sample configuration demonstrates static-file patterns with cache headers. Choose a policy that matches your release process: a long cache lifetime requires versioned filenames or another way to ensure browsers receive changed content. Do not apply an aggressive asset policy to files whose name stays constant unless you also have a reliable cache-invalidation plan.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Place the block in the active configuration
Nginx packages organize configuration differently. One installation may load a single main file with included snippets; another may provide a directory for available server blocks and a separate directory for enabled ones. Do not assume that editing a similarly named file changes the running service.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →- Find the main configuration file used by the installed package and inspect its
httpsection and include directives. - Identify the file that is actually included for virtual servers, or add the block to the active file if the package uses one file.
- Ensure the block is nested under
http, not undereventsor at the top level. - Check for another server block using the same port and a competing hostname. A packaged default block can answer requests when the hostname does not match yours.
Operating-system package paths and service names are local details. If you are unsure which file is active, inspect the package’s include structure and the command output available on that host rather than copying a path from another operating system.
Validate, reload, and verify
1. Test syntax before touching the running service
Run the platform’s Nginx configuration test. The customary command is:
Best Value
nginx -t
A successful test checks syntax and reports whether the referenced configuration can be loaded. If the package supplies a wrapper, use that wrapper’s equivalent test command. Fix every reported error before reloading; a typo in one included file can prevent the complete configuration from loading.
2. Reload without stopping active connections
Use the service manager supplied by the operating system or Nginx’s control command to reload the configuration. The Nginx control form is commonly:
Free tools Windows power users keep installed
One-click scans. No signup required.
nginx -s reload
Service-manager command names and permissions vary by platform, so use the local manager’s reload action when that is how Nginx was installed. A reload applies the validated configuration to new workers while allowing existing work to finish; a full stop and start is not normally required for a configuration-only change.
3. Exercise both success and failure paths
Request the site by a hostname that matches server_name. Check all of the following:
/returns the intended index document./about.htmlreturns the expected second page.- A known image, stylesheet, or script returns the correct file.
- An intentionally missing URI returns 404 when the configuration ends with
=404. - The response is coming from the intended virtual server, not a packaged default block.
You can perform the checks in a browser or with an HTTP client such as curl. Inspect the status code and the returned body; a visually similar default page can hide a hostname or server-selection error.
Troubleshooting common failures
| Symptom | Likely cause | What to check |
|---|---|---|
404 for / |
The index file is absent, the root points elsewhere, or the request reached another server block. | Confirm the exact path to index.html, the active root, the hostname in the request, and the result of nginx -t. |
| 404 for a known HTML file | The URI-to-filename mapping is not the one you expect, or the filename’s case differs. | Append the URI to the configured root manually and verify that the resulting file exists at that exact path. |
| A default Nginx page appears | The request matched a packaged default server or the requested hostname does not match your server_name. |
Inspect competing server blocks on the same listen address and test with the intended Host name. |
| 403 or a permission error | The worker process cannot traverse a parent directory or read the file. | Check ownership and read/execute permissions for the service account on every directory component and on the file itself. |
| Configuration test fails | A directive is outside its valid context, a semicolon or brace is missing, or an included file is invalid. | Read the filename and line number in the test output, verify the block is inside http, and test again after each correction. |
| The new configuration has no effect | The edited file is not included, or Nginx was not reloaded successfully. | Trace the active include structure, run the syntax test, perform a reload, and then request a file whose content clearly changed. |
| A fallback loops or still returns an error | The fallback URI is also processed by a rule that sends it back to itself, or the fallback file is missing. | Request the fallback URI directly, verify its root mapping, and keep the fallback location more specific than the general location /. |
Practical checklist before you publish the site
- The document root is an absolute directory that exists on the server.
index.htmlis inside that directory and is readable by Nginx.- The
serverblock is insidehttpand uses the intendedlistenport. - Every hostname users will enter appears in
server_name, or a deliberately chosen wildcard covers it. - The active
locationmaps each URL to the expected filesystem path. try_fileshas an intentional final action: a status such as=404or a real fallback URI.- Asset-specific locations, aliases, and cache rules have been tested with real files.
- The platform’s syntax test succeeds before every reload.
- After reloading, you have tested the home page, a second HTML page, an asset, and a missing URL.
Once those checks pass, Nginx is doing exactly what a static HTML server should: selecting the intended virtual host, translating each URI into a controlled filesystem lookup, serving existing content, and returning a predictable error for content that is not present.
Quick Recap
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.




