Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween 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 Enable Clean URLs for Drupal on Nginx

Set up Drupal clean URLs on Nginx by pointing to the correct web root, routing virtual paths through index.php, configuring PHP-FPM and troubleshooting missing routes or assets.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Drupal clean URLs normally work automatically, but Nginx must route every non-file path to Drupal’s front controller. Set the server’s root to the directory containing Drupal’s index.php, add try_files $uri /index.php?$query_string; to the main location, and pass PHP requests to the correct PHP-FPM socket or upstream. Then test and reload Nginx. This fixes the common case where /index.php works but routes such as /user/login return 404.

What Drupal clean URLs are—and why Nginx needs a rule

A clean Drupal URL is a path such as /node/83. The legacy form includes a query parameter, for example /?q=node/83. Drupal’s current documentation says clean URLs are enabled by default and cannot be disabled. The setting in Drupal is therefore usually not the problem; the web server must deliver the request to Drupal’s routing system.

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.

Apache can read per-directory rewrite rules from .htaccess. Nginx does not read .htaccess, so the equivalent front-controller behavior has to be written in the Nginx server configuration. Nginx 1.1 or newer is supported by Drupal on UNIX/Linux, macOS and Windows, subject to the requirements for your installed Drupal version.

The routing rule has two jobs. It serves a real file directly, such as an image, stylesheet or JavaScript file. If no file exists at the requested path, it internally sends the request to Drupal’s index.php and keeps the original query string. PHP-FPM then executes that script. If either the fallback or PHP handler is missing, a clean-URL failure can look like a Drupal problem even though the request never reaches Drupal correctly.

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

Before editing Nginx: identify the actual Drupal web root

Your Nginx root must be the directory that contains the front controller Drupal should execute. Do not assume it is the directory where the repository or Composer files live.

  • Find the intended index.php for the site.
  • For a Composer-based project, check the web directory first. A common layout is /var/www/drupal/web/index.php, while the project root is one level above it.
  • For a non-Composer installation, the document root may be the directory that directly contains Drupal’s core files and index.php.
  • If several Drupal sites are installed, identify the root separately for each server block or multisite entry.

Use the path that exists on the machine, not the example path in this article. A valid rewrite rule pointed at the wrong directory still produces 404 responses, missing assets or PHP errors.

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.

Recommended Nginx configuration

The following pattern covers the essential routing and PHP-FPM requirements:

server {
    server_name example.com;
    root /var/www/drupal/web;
    index index.php;

    location / {
        try_files $uri /index.php?$query_string;
    }

    location ~ .php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}

Replace example.com, the root path and the PHP-FPM endpoint with your local values. The important fallback is try_files $uri /index.php?$query_string;. $uri lets Nginx serve an existing file; the second argument sends an unmatched path to Drupal while preserving query parameters.

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.

The PHP location must match the way PHP-FPM is installed. A Unix socket such as unix:/run/php/php-fpm.sock is only an example. Some systems expose PHP-FPM through a versioned socket, while others use a TCP address and port. The value after fastcgi_pass must be the endpoint that PHP-FPM is actually listening on.

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; gives PHP-FPM the full path to the requested script. If your distribution’s packaged FastCGI include supplies equivalent parameters, you may use it instead of duplicating them. Confirm what the include contains rather than assuming it sets the correct document root.

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

Enable the configuration step by step

  1. Locate the front controller. Verify the full path to the index.php that should receive Drupal routes. In a Composer layout, this is often inside web, not the repository root.
  2. Set the server root. In the Nginx server block that handles the domain, set root to that directory and include index index.php;. Make sure this is the server block selected for the hostname you are testing.
  3. Add the front-controller fallback. Inside location /, add try_files $uri /index.php?$query_string;. Keep the query-string suffix so existing parameters reach Drupal.
  4. Configure PHP execution. Add or correct the PHP regular-expression location. Include the FastCGI parameters, set SCRIPT_FILENAME to the resolved document-root path, and set fastcgi_pass to the real Unix socket or TCP upstream.
  5. Check file access. The Nginx worker must be able to read Drupal’s code. Drupal’s public-files directory must also be writable wherever the site needs to create uploads, generated image styles or other public assets. Use the ownership and permissions appropriate to your operating system rather than making the whole project world-writable.
  6. Validate syntax. Run nginx -t. Do not reload a configuration that reports a syntax error; correct the reported file and line first.
  7. Reload Nginx. After a successful test, reload Nginx through your operating system’s service manager so existing connections can finish while workers adopt the new configuration. The exact service command varies by distribution.
  8. Test a known route. Request /user/login or another route that is known to exist, without adding ?q=. Then check the page’s CSS, JavaScript and image requests in the browser and inspect Nginx and PHP-FPM logs if anything fails.

How to verify that clean URLs are working

Test the layers separately so a failure points to the right component:

  • Front controller: Open the site’s /index.php. If it fails, fix the server root, PHP handler or Drupal bootstrap before investigating rewrites.
  • Dynamic route: Open /user/login or another known route. A successful response confirms that the unmatched-path fallback is reaching Drupal.
  • Static asset: Request a real CSS, JavaScript or image file from the public-files location. Static 404s often indicate an incorrect public-files path or permissions rather than a routing rule.
  • Query preservation: Test a route that legitimately uses query parameters and verify that Drupal receives them. The fallback’s $query_string component is what preserves them.
  • Logs: Correlate the request timestamp in the Nginx error/access logs and PHP-FPM log. A 404, 403, 502 and PHP application error indicate different classes of failure.

Use a browser’s network panel or a command-line HTTP client to see the status code and final redirect. A route that returns a Drupal page but has failed asset requests is not fully fixed; check each asset request independently.

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

Troubleshooting Drupal on Nginx

Symptom What to check first Why it happens
/user/login returns 404, but /index.php works Confirm the active server block, its root, and the location / fallback. Nginx is serving the site but is not sending unmatched paths to Drupal, or the request is reaching a different server block.
CSS, JavaScript or image styles return 404 Check the configured public-files path, the physical files, permissions and any location block that handles static files. Static requests may point outside the configured root, the files may not have been generated, or another location may intercept them.
PHP source downloads or PHP requests return 404 Inspect the PHP location, its ordering and the fastcgi_pass endpoint. Nginx is not handing PHP files to PHP-FPM, or the request is being handled by the wrong server block.
502 Bad Gateway Check whether PHP-FPM is running, whether the socket or TCP address is correct, and whether Nginx can access the socket. Nginx cannot connect to the configured FastCGI upstream.
Routes work at the domain root but fail in a subdirectory Adapt the document root, front-controller fallback and path-prefix handling to the actual subdirectory installation. A configuration written for a domain-root site does not automatically account for a URL prefix.
Login redirects to the wrong scheme or host behind a proxy Review Drupal’s reverse-proxy and forwarded-header settings as well as Nginx routing. The application may not know the original HTTPS scheme or host supplied by the proxy.

When every clean route is a 404

Start by confirming which Nginx server block answered the request. A default server or another virtual host can have a different root and no Drupal fallback. Check the hostname, listen directives and any included configuration files. Next, verify that the configured root contains the same index.php you tested directly. If the root is the repository directory while the front controller is in web, Nginx will look in the wrong place.

If the server block and root are correct, inspect the location / block for a missing or mistyped fallback. A rule that only uses try_files $uri =404;, for example, deliberately returns 404 for virtual Drupal paths because no physical file exists. The fallback must target Drupal’s front controller.

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.

When only assets fail

Inspect one failing asset URL and map it to the filesystem under the configured root. Drupal’s public-files directory must be present at the path Drupal expects, and the Nginx worker must be able to traverse its parent directories and read the files. Generated image styles and uploads additionally require write access for the Drupal process. Avoid solving a permission problem by granting unrestricted access to the entire installation.

Also check for a more specific Nginx location that captures asset extensions or a separate alias for files. Such a block can bypass the normal root or point to a directory that does not contain Drupal’s public files.

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.

When PHP fails after the rewrite is fixed

A working fallback does not execute PHP by itself. Confirm the PHP regular-expression location is loaded in the active server block and that its fastcgi_pass value matches PHP-FPM’s configured listener. A versioned Unix socket path copied from another machine is a frequent cause of 502 errors. For TCP, verify both the address and port and ensure the service is listening there.

Check SCRIPT_FILENAME next. It must resolve to the real path of the requested PHP file under the configured root. If it resolves to a non-existent path, PHP-FPM may return a file-not-found error even though Nginx can see the request.

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

When the configuration passes syntax but still does not apply

nginx -t validates syntax and referenced files; it does not prove that the intended server block wins for a particular hostname. Confirm that the configuration was reloaded after editing, that the hostname resolves to this machine, and that no load balancer or reverse proxy is sending the request elsewhere. Compare the response headers and logs from the request you are testing with the server you changed.

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

Deployment variations to plan for

Domain root versus subdirectory

A domain-root site can use a root such as /var/www/drupal/web and a fallback to /index.php exactly as shown. A site published under a URL prefix, such as /drupal, needs a configuration that reflects that prefix and the directory layout. Do not simply prepend a string to the example without checking how Nginx maps the URI and where Drupal’s front controller resides. Test both a dynamic route and a static file beneath the prefix.

Unix socket versus TCP PHP-FPM

A Unix socket is referenced with the unix: prefix and a filesystem path. Nginx needs permission to connect to that socket. A TCP upstream uses an address and port instead, so filesystem permissions on a socket are not involved, but the network listener and any local firewall policy must be correct. The routing rule for Drupal is the same; only the FastCGI transport endpoint changes.

Single site versus multisite

For a single site, one server block and one Drupal web root are usually sufficient. Multisite deployments can share code while selecting different site directories, hostnames or database configurations. Give each hostname the correct root and application settings, and verify that a fallback does not expose another site’s files. Keep site-specific public and private file locations separated according to Drupal’s security guidance.

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

Direct Nginx termination versus a reverse proxy

When Nginx terminates TLS and serves Drupal directly, its server block receives the original host and scheme. When another proxy or load balancer sits in front, Nginx may receive an internal address or HTTP connection instead. Routing still requires the same front-controller behavior, but Drupal must be configured to trust and interpret the forwarded host and scheme correctly. Restrict trusted proxy settings to the infrastructure you control; accepting arbitrary forwarded headers can create security and redirect problems.

Self-managed server versus managed Drupal hosting

Self-management gives you control over Nginx, PHP-FPM sockets, filesystem permissions and reloads, but you are responsible for keeping those layers aligned with the Drupal release and project layout. Managed Drupal hosting is an alternative when you do not have root access or do not want to maintain the web-server and PHP runtime. Ask the provider which web root, PHP-FPM arrangement and subdirectory or proxy options it supports, and confirm that you can inspect logs when a route or asset fails.

Security and maintenance checks

  • Keep the Nginx root limited to Drupal’s intended web directory. A Composer project’s repository root may contain files that should never be directly downloadable.
  • Protect Drupal’s private files and sensitive directories using the current Drupal security guidance and an explicit Nginx policy. Do not assume that the front-controller fallback alone protects every directory.
  • Review custom aliases, regular-expression locations and deny rules after Drupal or module changes. A more specific location can override the behavior you expect from location /.
  • Keep the PHP-FPM version, socket path and Nginx FastCGI parameters synchronized after upgrades. A runtime upgrade can change the socket name without changing your Drupal files.
  • Retest a dynamic route, a CSS or JavaScript file and an uploaded or generated asset after configuration changes. A successful home page is not proof that all three request types work.
  • Save a known-good configuration and the output of nginx -t before making a larger change. If a reload fails, restore the last valid version and investigate the reported line.

Quick diagnosis checklist

  1. Does the active server block’s root contain the intended index.php?
  2. Is index.php listed in the server’s index directive?
  3. Does location / use the Drupal fallback with $query_string?
  4. Does the PHP location include equivalent FastCGI parameters and a valid SCRIPT_FILENAME?
  5. Does fastcgi_pass point to a running PHP-FPM socket or TCP listener?
  6. Can the Nginx worker read Drupal code and the public-files directory?
  7. Is the public-files directory writable where Drupal must create uploads or generated assets?
  8. Did nginx -t pass, and was Nginx reloaded afterward?
  9. Are you testing the same hostname, proxy path and subdirectory that the edited server block handles?
  10. What status code and log entry correspond to the failing request?

The Bottom Line

For Drupal on Nginx, clean URLs are enabled by default; the essential work is correct server routing. Point root at the directory containing Drupal’s front controller, use try_files $uri /index.php?$query_string;, connect PHP requests to the real PHP-FPM endpoint, verify permissions, test with nginx -t, reload, and diagnose any remaining 404, 403 or 502 through the matching 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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.