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

To serve a static HTML site with Nginx, place the files in a directory, point a server block at that directory with root, set index index.html, and use try_files to return existing files or a deliberate 404. Test the active configuration, reload Nginx, then request the home page, a known file, an asset, and a missing path.

Use this minimal configuration

Create a server block in the Nginx configuration loaded by your installation. This example serves files from /data/www for two host names:

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

    root /data/www;
    index index.html;

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

Create /data/www/index.html, plus files such as /data/www/about.html. A request for /about.html maps to /data/www/about.html. A request for / uses the configured index file. A request for a path that does not identify an existing file or directory returns HTTP 404 because of the final =404 fallback.

The server block must be inside the configuration’s http context. The exact file that contains the active block depends on how Nginx was packaged for your operating system, so confirm which configuration your running instance loads instead of editing a similarly named, unused file.

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

What each directive controls

Directive Purpose Effect in this static site
listen Selects the local address and port accepted by the virtual server Accepts HTTP connections on port 80
server_name Matches the host name from the request Matches example.com and www.example.com
root Sets the filesystem directory used to construct file paths Appends the request URI to /data/www
index Defines files to try when a request identifies a directory Checks index.html for the site root
location Controls which requests use a set of directives Applies the static-file rules to requests beginning with /
try_files Checks candidate files or directories in order Tests the requested path, then its directory form, then returns 404

Prepare the files and configuration

Create a document root

Choose a directory that will contain only the files you intend to publish. The Beginner’s Guide uses /data/www; you can use another absolute path if it matches your server layout. Keep the path consistent between the filesystem and the root directive. Nginx does not search your whole machine for an HTML file: it constructs a specific path from the active root and the request URI.

Add an index and a second page

Create an index.html in the root directory and, for example, an about.html beside it. The filenames are case-sensitive on systems whose filesystems are case-sensitive. If the file is named Index.html but the configuration asks for index.html, the index lookup will not find it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<!doctype html>
<html lang='en'>
<head>
  <meta charset='utf-8'>
  <title>Example site</title>
</head>
<body>
  <h1>It works</h1>
  <p>This page is served as a static file by Nginx.</p>
</body>
</html>

Save the document as /data/www/index.html. A link such as <a href='/about.html'>About</a> requests the second file directly; no application runtime is needed for either page.

Find the packaged configuration path

Installations differ in how they divide configuration files. Some use a main nginx.conf with an include directory; others enable individual virtual-host files through a package-specific directory. Edit the file that is actually included by the running Nginx process, and ensure the server block is nested under http. If you edit a file that is not included, syntax tests and reloads can succeed while the live site remains unchanged.

How Nginx turns a URL into a file

1. Select a virtual server

Nginx first considers the listening address and port, then compares the request’s host name with available server_name values. Names can be exact, wildcard, or regular-expression names. An exact name such as example.com is appropriate when one site should answer for one known host. If several server blocks listen on the same address and port, a request whose host does not match the intended block can be handled by another block, often the package’s default site.

2. Select a location

After choosing a server, Nginx evaluates its location directives. The location / block is a broad prefix match for ordinary site requests. More specific locations can handle an asset directory, a custom error document, or another path with different rules. The selected location determines which root or alias applies while Nginx constructs the filesystem path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

3. Construct the path with root

With root /data/www, Nginx appends the request URI to that directory. The URI /about.html therefore becomes the local path /data/www/about.html. For a request such as /images/logo.svg, the same root would produce /data/www/images/logo.svg.

root is a directory mapping, not a filename setting. Do not set it to /data/www/index.html; doing so would make path construction incorrect for other requests. Use index to name the default document instead.

How the home page is found

The index directive defines files used as an index. In the example, a request for / causes Nginx to check index.html in the mapped directory. The documented default is also index.html, but declaring it explicitly makes the intended behavior visible and avoids confusion when another configuration changes the inherited value.

Index filenames are checked in the order configured. You could list more than one filename when a site has a deliberate fallback, but every listed name should exist where it is expected and should be treated as a published document. Finding an index causes an internal redirect to that file’s URI; Nginx processes that URI through location selection again. Consequently, a more specific location can affect how the index file is ultimately served.

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.

If index.html is absent, the result depends on the rest of the configuration and the directory’s handling. A directory may produce an error rather than a page. The most predictable static-site behavior is to keep the index file present and use try_files for explicit missing-path handling.

Use try_files for predictable 404 responses

The directive try_files checks candidates in order and uses the first one that exists. Each candidate is converted into a path using the active root or alias. In the minimal configuration:

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.
try_files $uri $uri/ =404;
  • $uri tests the requested URI as a file or path.
  • $uri/ tests the directory form, allowing a directory request to proceed to index processing.
  • =404 stops processing with an explicit HTTP 404 when neither candidate exists.

This ordering means /about.html is served when the file exists, while a directory such as /docs/ can continue to its index handling. A typo such as /abotu.html does not fall through to an unrelated default document; it receives 404.

The final argument can instead be a URI for a fallback page. If you choose that design, define a corresponding location and make sure the fallback itself exists. Ordered checks can also include paths such as $uri/index.html or $uri.html when the site’s URL design requires them, but adding fallbacks changes which requests return content and should be intentional.

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

Serve assets from a separate directory

A site can keep images or other static assets outside the main document root. The Beginner’s Guide demonstrates this mapping:

location /images/ {
    root /data;
}

With that location, a request for /images/logo.svg maps beneath /data, producing /data/images/logo.svg. The location-specific root overrides the broader root for matching requests. Verify the resulting path on disk before troubleshooting the browser: the URL prefix and the filesystem directory must line up exactly.

Use a separate location when the directory genuinely needs different treatment, such as cache headers or a distinct filesystem boundary. Otherwise, keeping assets under one document root is easier to audit because every URL follows the same mapping rule.

Add a custom 404 page and cache rules

Nginx’s example configuration includes a custom /404.html location and static-file patterns with cache headers. A simple arrangement is to place 404.html in the document root, configure an error-page URI, and define a location for that file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
error_page 404 /404.html;

location = /404.html {
    root /data/www;
}

The custom page must be a real file. Test a missing URL after reloading and confirm that the response status remains 404 even though the body is your friendly error document. If a fallback should return a normal page with status 200 instead, that is a different behavior and should be configured deliberately.

Long-lived cache headers can reduce repeat downloads for versioned assets such as files whose names change whenever their contents change. Apply cache rules only to the locations and file patterns for which that policy is appropriate. Do not cache an HTML entry document for a long period if you expect it to change without a filename change; visitors could continue seeing an older copy.

Check ownership and permissions

Nginx worker processes must be able to traverse every parent directory and read the files they serve. A correct root with unreadable files still produces an error. Check the directory permissions, file permissions, and ownership used by the Nginx worker account on your operating system. Also check any operating-system access-control mechanism that can deny reads even when traditional mode bits look correct.

  • Confirm that the configured root directory exists.
  • Confirm that each parent directory allows traversal by the worker account.
  • Confirm that index.html and assets are readable.
  • Check that a separate asset root, if used, has the same access requirements.
  • Keep private files outside the document root rather than trying to hide them with a URL convention.

Do not solve a read failure by making the entire filesystem or every file world-writable. Grant the minimum directory traversal and read access required by the Nginx worker processes.

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

Test, reload, and verify the live site

  1. Place index.html, any additional HTML files, and known assets in the configured root.
  2. Edit the active configuration and confirm that the server block is inside the http context.
  3. Run the platform’s Nginx syntax test. nginx -t is the customary command, but package wrappers and privilege requirements differ.
  4. Only after a successful test, reload Nginx through the service manager or the Nginx control command supplied by your operating system. The appropriate reload command is platform-specific; use the method documented for your installation.
  5. Request the home page, a known HTML file, a known asset, and an intentionally missing path.
Request Expected result What it verifies
/ HTTP 200 with the contents of index.html Server selection, root mapping, and index handling
/about.html HTTP 200 with the about page Direct file mapping
A known asset path HTTP 200 with the asset Asset location and permissions
An intentionally missing path HTTP 404, optionally with the custom error body try_files and error handling

Use a request tool or browser developer tools to inspect the status code and response body. A browser can retain cached content, so compare the returned URL, status, and response headers when a recent edit appears not to have taken effect.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

The browser shows a 404 for a file that exists

  • Compare the URL’s path and capitalization with the actual filename.
  • Calculate the path Nginx should use by appending the URI to the active root. Check that exact path on disk.
  • Verify that the request matched the intended server_name and listen pair rather than a default server.
  • Check whether a more specific location changed the root or alias.
  • Inspect try_files ordering and its final fallback. A candidate that is not present will continue to the next candidate.

The home page is not displayed at /

Check that the directory contains the configured index filename and that the worker can read it. Confirm that index index.html; appears in the server or applicable location context. If the request is being handled by another server block, correct the host name or virtual-server selection first.

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.

Nginx returns 403 for a directory

A directory request normally needs an index file. Add the expected index.html, ensure it is readable, and make sure parent directories are traversable. If directory listing was never intended, returning an error for a directory without an index is preferable to exposing a file listing.

Nginx serves an old or unexpected page

Check which server block answered the request by verifying the host name and port. Remove or disable an unintended default site only through your operating system’s package conventions. Then test the configuration and reload. Also check browser or intermediary caches when the response headers permit caching.

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

The syntax test fails after an edit

Read the reported file and line number, then check braces, semicolons, directive spelling, and context. A server block placed outside http is a structural error. Do not reload a configuration that fails the syntax test; restore the last known-good version, test again, and then make one change at a time.

Choose a configuration pattern deliberately

One document root

Use one root when HTML, images, stylesheets, and scripts form one site and share the same access policy. The mapping is easy to predict: append each URI to the same directory, and keep one broad location / with the ordered try_files check.

Separate asset roots

Use location-specific roots when assets live in another directory or require a different cache policy. Document the URL-to-path mapping for each location so future changes do not create files in a directory Nginx never reads.

Implicit versus explicit index handling

Relying on the documented index.html default can work for a minimal installation, but an explicit index index.html; communicates the contract in the server block. Explicit configuration is especially useful when inherited settings or included files may change later.

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.

Direct 404 versus a fallback URI

Use =404 when nonexistent URLs should fail clearly. Use a fallback URI only when the site has a defined error or routing page and the fallback’s status and location behavior have been tested. Every additional fallback makes it possible for a typo to display content that was not intended for that URL.

Exact host names versus wildcard names

List exact host names when the site should answer only for known domains. Wildcard or regular-expression names can cover families of hosts, but they also broaden matching and make it easier for an unexpected host to reach the server block. Test the host names you intend to support and the host names you do not.

Operational checklist

  • The requested host and port match the intended server block.
  • The server block is inside http and is included by the running Nginx configuration.
  • The root is an absolute directory containing the published files.
  • index.html exists with the expected capitalization.
  • try_files $uri $uri/ =404; appears in the static location when explicit 404 behavior is desired.
  • Asset locations map to directories that actually exist.
  • Nginx workers can traverse directories and read files.
  • nginx -t, or the installation’s equivalent syntax test, succeeds before every reload.
  • After reloading, tests cover the home page, a direct HTML file, an asset, and a missing path.

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.