Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Secure Nginx With NAXSI on an Ubuntu VPS

A practical, location-aware guide to securing NGINX with NAXSI on Ubuntu: install the matching module, load core rules, tune in learning mode, whitelist safely, and switch to blocking without locking out legitimate users.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

NAXSI adds a web application firewall (WAF) directly to NGINX. On an Ubuntu VPS, the safe deployment path is to install a module built for the exact NGINX version, load NAXSI’s core rules in http{}, enable it only in the application locations you intend to protect, run in learning mode while you exercise real traffic, review the events, add narrow whitelist rules, and then switch to blocking mode.

What NAXSI changes in an NGINX deployment

NAXSI is an open-source WAF implemented as an NGINX module. It is configured inside NGINX; it is not a separate reverse proxy that you put in front of your web server. The module examines requests handled by NGINX, assigns scores to suspicious patterns, and applies rules that either allow, log, or block the request.

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.

The project describes NAXSI as a high-performance WAF with low rule-maintenance requirements. Its security model is different from a conventional signature-only filter: NAXSI behaves as a drop-by-default firewall. Legitimate application behavior must therefore be accepted with whitelist rules, especially when a valid request contains characters or parameter values that also resemble an injection attempt.

Three NGINX configuration scopes matter:

  • http{}: load the core rule set that defines the detection patterns.
  • server{}: include the denied-request handler and any server-level modifiers.
  • location{}: enable NAXSI for a particular URL path, select learning or blocking mode, add whitelists, and set the score thresholds that trigger a block.

Because enforcement is location-scoped, your public application, an upload endpoint, an API, and a health-check path can have different policies. That control is useful, but it also means that adding NAXSI to one location does not automatically protect every location in the virtual host.

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

Prepare the Ubuntu VPS before changing NGINX

Make the change during a maintenance window. A syntax error or an incompatible module can prevent NGINX from reloading, and an over-broad rule can reject normal requests.

Prerequisites

  • An Ubuntu VPS with administrative access through sudo or a root shell.
  • A working NGINX site whose configuration and upstream application have already been tested.
  • A backup of /etc/nginx, the active virtual-host files, and any custom NAXSI rules.
  • Access to the same NGINX package source or source tree used to build the running binary.
  • A way to observe the NGINX error log and application behavior while you test.

Record the current state before installing anything. A simple backup gives you a fast recovery path:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo cp -a /etc/nginx /etc/nginx.backup-$(date +%F)

Do not assume that a module compiled for one Ubuntu image, repository, or NGINX minor release will load into another. NGINX checks module compatibility, and a mismatch can produce an “is not binary compatible” error at startup.

Check the running NGINX version and build

First identify the exact binary and compile options that are serving traffic.

nginx -v
nginx -V 2>&1

The first command prints the version. The second prints the configure arguments and module information. Save this output; it is the reference for a packaged-module search or a dynamic-module build.

Keep the package source consistent

Use an official Ubuntu-compatible NGINX package source and keep the NGINX package, service files, and module package from the same source where possible. Ubuntu repositories do not expose the same NAXSI package for every release, so availability is release-dependent.

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.

Before installing a module, check what your configured repositories offer:

sudo apt update
apt-cache search naxsi

If the result includes a module package for your release, inspect its package metadata and install that package rather than guessing a filename. If no compatible package is available, build a dynamic module against the exact NGINX version reported by nginx -v.

Install NAXSI: packaged module or matching dynamic build

Option A: install a packaged module

A packaged module is usually the least error-prone route because the distribution maintains the module’s ABI relationship with its NGINX package. Install the NAXSI module package offered by your Ubuntu release, then verify that the package installed a shared object and the standard rule files.

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 apt install <the-naxsi-module-package-for-your-ubuntu-release>
ls -l /usr/share/naxsi/
find /usr/lib /lib -name '*naxsi*.so' 2>/dev/null

The package layout documented for Debian and Ubuntu includes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • /usr/share/naxsi/naxsi_core.rules
  • /usr/share/naxsi/naxsi_denied_url.conf
  • either /usr/share/naxsi/naxsi_block_mode.conf or /usr/share/naxsi/naxsi_learning_mode.conf

The exact shared-object directory can differ between Ubuntu releases. Use the path installed by the package when you write the load_module directive.

Option B: compile a dynamic module for the running NGINX

When Ubuntu does not provide a compatible package, compile NAXSI as a dynamic module using the NGINX source that matches the running binary. Do not compile against an arbitrary newer source release and expect it to load safely.

  1. Install the compiler, linker, and development libraries required by your NGINX source and Ubuntu release.
  2. Obtain the NGINX source for the exact version shown by nginx -v.
  3. Obtain the NAXSI source tree and identify its NGINX module directory.
  4. Configure the NGINX source with compatibility enabled and NAXSI added as a dynamic module. A typical build shape is:
./configure --with-compat --add-dynamic-module=/path/to/naxsi/module
gmake modules

On Linux the build command is normally make modules; use the command expected by the source tree you downloaded. The important requirement is that the module is built from the same NGINX version and compatible configure environment as the binary that will load it.

  1. Copy the resulting ngx_http_naxsi_module.so to the modules directory used by your NGINX installation, preserving ownership and readable permissions.
  2. Run nginx -t before attempting a reload. If NGINX reports an ABI or undefined-symbol error, stop and rebuild against the matching source rather than forcing the service to start.

Keep the build notes and the source versions with your server documentation. A future NGINX upgrade may require rebuilding the module before the service can be restarted.

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

Load the module and arrange the NAXSI configuration layers

Load the dynamic module once, at the top level of the NGINX configuration, before the events{} and http{} blocks. Use the path installed by your package or build:

load_module modules/ngx_http_naxsi_module.so;

Some Ubuntu installations use an absolute path under /usr/lib/nginx/modules/. Substitute the actual path; do not copy a path from a different package layout.

Load the core rules in http{}

Inside the main http{} block, include the core rules once:

http {
    include       /usr/share/naxsi/naxsi_core.rules;

    # existing MIME, logging, upstream, and virtual-host includes
}

The core file defines the detection patterns. Loading it does not by itself protect a location; enablement belongs in each location that should be inspected.

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

Define the denied-request endpoint in server{}

Inside the relevant virtual host, include the distribution’s denied URL configuration:

server {
    listen 443 ssl;
    server_name example.invalid;

    include /usr/share/naxsi/naxsi_denied_url.conf;

    # application locations follow
}

The supplied file provides the endpoint NAXSI uses when a request is denied. Keep that endpoint outside the protected application location, or a blocked request can be sent back through the same inspection rule and create a loop. If you maintain your own denied handler, make it a simple, unprotected response that does not depend on the application.

Enable NAXSI in one application location

Start with the narrowest location that serves your application. The following example shows the directives and the documented score thresholds as starting points:

server {
    listen 443 ssl;
    server_name example.invalid;

    include /usr/share/naxsi/naxsi_denied_url.conf;

    location / {
        proxy_pass http://app_backend;

        SecRulesEnabled;
        LearningMode;
        DeniedUrl "/RequestDenied";

        include /usr/share/naxsi/naxsi_learning_mode.conf;

        CheckRule "$SQL >= 8" BLOCK;
        CheckRule "$RFI >= 8" BLOCK;
        CheckRule "$TRAVERSAL >= 5" BLOCK;
        CheckRule "$UPLOAD >= 5" BLOCK;
        CheckRule "$XSS >= 8" BLOCK;
    }
}

Use the denied URL configured by your installed file if it differs from the example. The score values above are documented examples, not universal safe settings. An application that accepts rich search syntax, encoded data, or unusual upload fields may need different thresholds after you review real requests.

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

Do not place both mode files in the same location. Include the learning-mode file while tuning; later replace it with the block-mode file. Keeping both creates an ambiguous policy and makes troubleshooting difficult.

Run learning mode against real traffic

Learning mode lets NAXSI observe requests and report which rules would have contributed to a decision without immediately rejecting normal users. It is not a substitute for testing: exercise every legitimate feature yourself and, if possible, have application owners or a staging test suite generate representative requests.

Exercise the complete request surface

  • Open anonymous and authenticated pages.
  • Submit every form, including validation errors and searches.
  • Test file uploads with the formats your application accepts.
  • Use API methods with JSON, query strings, cookies, and authorization headers.
  • Test administrative paths separately from public paths.
  • Trigger redirects, pagination, filtering, and any endpoint that accepts encoded or user-generated text.

Watch the NGINX error log and the NAXSI events produced by your build. The event identifies the URL, request zone, matched pattern, and score contribution. Correlate it with the application request and decide whether the behavior is expected before writing a whitelist.

Why learning mode still needs review

NAXSI’s simple patterns can match valid queries. A search term, markup fragment, serialized object, or upload field may look like SQL, XSS, traversal, or remote-file-inclusion input even when the application expects it. Automatically accepting every generated suggestion can create a broad exception that weakens protection.

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.

For each event, record:

  • the exact URL and HTTP method;
  • the parameter, header, cookie, or body field that matched;
  • the rule category and score;
  • whether the value is required for a documented feature;
  • the smallest scope in which the exception is valid.

Write narrow whitelist rules

Whitelist only behavior you can explain. Prefer a rule tied to one URL and one parameter over a global rule that accepts a pattern everywhere. The exact syntax depends on the NAXSI version, so use the generated event and the syntax documented for the module installed on your server.

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 typical location-and-argument rule has this shape:

BasicRule wl:1 "mz:$URL:/search|$ARGS_VAR:q";

This example allows the named argument only on the specified path. A body-field or URL-specific exception can be expressed in the same way by selecting the appropriate measurement zone shown in your event.

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

Whitelist review rules

  • Scope it: include the exact path, parameter name, method, or zone that needs the exception.
  • Keep it local: place the rule in the protected location or an included file used only by that application.
  • Document the reason: write a comment with the feature, owner, and date.
  • Retest the negative case: confirm that unrelated paths and parameters still trigger detection.
  • Remove stale exceptions: delete a whitelist when the application stops using the behavior.

Avoid a global “allow everything” rule and avoid whitelisting an entire request body merely because one field is legitimate. If a form accepts markup, constrain the application’s accepted format as well; NAXSI cannot compensate for an application that treats untrusted content as executable HTML.

Move from learning mode to blocking mode

Switch only after normal traffic has been exercised and the remaining events are either malicious or understood. Make a backup of the tuned rules, then replace the learning include with the block include in the protected location:

location / {
    proxy_pass http://app_backend;

    SecRulesEnabled;
    DeniedUrl "/RequestDenied";

    include /usr/share/naxsi/naxsi_block_mode.conf;

    # reviewed BasicRule whitelist entries
    # reviewed CheckRule thresholds
}

Remove LearningMode; when you use the block-mode configuration, and do not include naxsi_learning_mode.conf in this location. Keep the reviewed whitelists and thresholds explicit so a later administrator can see what was accepted and why.

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

Validate and reload safely

  1. Check the complete configuration:
sudo nginx -t
  1. Proceed only when the test reports a successful syntax check and a successful configuration test.
  2. Reload during the maintenance window:
sudo systemctl reload nginx
  1. Immediately request public pages, authenticated pages, forms, uploads, and API endpoints.
  2. Monitor the NGINX error log, application logs, response status, and the denied endpoint.
  3. If the reload fails, restore the last known-good configuration and run nginx -t again before restarting anything.

A reload is preferable to a stop-and-start because existing workers can finish active connections while the new configuration is tested. It does not remove the need for a maintenance window: a bad module or configuration can still prevent new workers from starting.

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

Use different policies for different locations

NAXSI’s location scope lets you make deliberate trade-offs instead of applying one exception to the entire site.

Location type Typical policy decision Reason to separate it
Public pages Use the normal score thresholds and a small whitelist set. These paths usually accept less structured input and should have a narrow attack surface.
Search and filtering Expect more legitimate special characters; tune only the named arguments that require them. Broad search syntax can create false positives if it is whitelisted globally.
Upload endpoint Review the upload score threshold, body handling, size limits, and accepted file types together. Uploads have different risk and traffic patterns from ordinary page requests.
JSON or API location Test each method and body field; create method- and path-specific rules. Machine clients often send structured content that public-page rules do not anticipate.
Health check or static files Protect only if dynamic input reaches the location; otherwise keep the handler simple. Unnecessary inspection adds policy complexity without protecting an application input.

Remember that a nested or more specific NGINX location may receive the request instead of the broad location /. Confirm the effective location when a request appears unprotected.

Troubleshoot common failures

NGINX says the module is not binary compatible

The module was built for a different NGINX version or incompatible build options. Compare nginx -v and nginx -V with the source and configure arguments used for the module. Install a matching packaged module or rebuild the dynamic module against the running version.

NGINX reports an unknown NAXSI directive

The module was not loaded, the load_module path is wrong, or the module failed to load before NGINX parsed the location. Check the shared-object path, file permissions, and the first error in nginx -t. Do not add directives until the module loads successfully.

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

The core rules file cannot be opened

Verify that the package installed /usr/share/naxsi/naxsi_core.rules and that the include path matches the file’s actual location. If you compiled NAXSI yourself, locate the installed rule file and use an absolute path. Keep the rules readable by the NGINX master process.

Every request is denied

Confirm that learning mode is active while tuning, that the denied URL is not itself protected, and that the score thresholds were not copied with a syntax error. Inspect the event for the rule category and request zone. Add a narrow whitelist only when the request is demonstrably legitimate; do not disable NAXSI for the whole server to solve one false positive.

Legitimate uploads or API calls fail after blocking is enabled

Reproduce the exact request in a controlled window, identify the field or body zone that matched, and add the smallest path- and field-specific exception. Re-test a malicious-looking value on another path to ensure the exception did not become global.

The site works, but a path appears unprotected

Inspect the NGINX location hierarchy. A regex, exact-match, or more-specific prefix location may handle the request instead of the location where you enabled NAXSI. Add the directives to every intended protected location and confirm with a test request and log event.

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

The denied response is confusing to users

Keep the denied endpoint simple and return a clear status or branded error page without echoing the rejected input. Do not proxy the denial back to the application, and do not expose rule scores or internal diagnostics to the client.

Operate NAXSI after deployment

Blocking mode is not a set-and-forget switch. Application releases can introduce new parameters, request formats, or upload workflows that need review.

  • Keep NAXSI rules in version control with the NGINX configuration.
  • Review denied events after every application release and after changes to forms or APIs.
  • Audit whitelist entries periodically and remove rules for retired features.
  • Test configuration changes with nginx -t before every reload.
  • Retain a rollback copy of the previous working configuration.
  • Watch resource usage and log volume; the available material does not establish a universal performance gain or loss for a particular VPS.

NAXSI reduces exposure to common malicious request patterns, but it does not patch vulnerable application code, enforce authentication, validate business permissions, or replace secure output encoding. Continue to update Ubuntu, NGINX, the NAXSI module, and the application, and use application-level validation for every input.

Deployment checklist

  • Record the running NGINX version and configure arguments.
  • Back up /etc/nginx and the active virtual-host files.
  • Install a module package compatible with the Ubuntu release, or build a dynamic module against the exact NGINX version.
  • Load the module once at top level.
  • Include naxsi_core.rules in http{}.
  • Include the denied URL configuration in the relevant server{}.
  • Enable NAXSI in each intended location{}.
  • Start with learning mode and exercise real site behavior.
  • Review events and create narrow, documented whitelists.
  • Replace learning mode with block mode only after false positives are addressed.
  • Run nginx -t, reload during a controlled window, and monitor responses and logs.

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
Windows Errors? Fix Them Before They SpreadFree repair scan

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.