October DealsAmazon USOctober deal check: compare before you payAmazon 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Enable Clean URLs for Drupal on Nginx

Drupal clean URLs work on Nginx when requests fall back to index.php and PHP-FPM is configured for the correct Drupal root. Follow this complete setup and troubleshooting guide.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To enable Drupal clean URLs on Nginx, route requests for nonexistent files to Drupal’s front controller with try_files $uri /index.php?$query_string;, then pass PHP requests to the correct PHP-FPM socket or upstream. Drupal clean URLs are enabled by default; Nginx must be configured to deliver them because it does not read Apache .htaccess files.

The most common failures are an incorrect Nginx root, a missing try_files fallback, or PHP-FPM settings that point to the wrong socket or file path. The procedure below identifies the correct web root, installs a safe server block, validates it, and diagnoses 404, 403, 502, and missing-asset errors.

As an Amazon Associate I earn from qualifying purchases.

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

What Drupal clean URLs are and why Nginx needs a rule

A clean Drupal URL is a path such as /node/83 or /user/login. The older non-clean form adds a query parameter, for example /?q=node/83. Drupal documentation states that clean URLs are enabled by default and cannot be disabled.

That default does not remove the web server’s responsibility. A request for /user/login normally does not correspond to a physical file named user/login. Nginx must therefore try the requested path, detect that no file exists, and forward the request to Drupal’s index.php. Drupal then interprets the path and generates the response.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Apache can express this behavior in .htaccess; Nginx does not use .htaccess. Its server block must contain the equivalent routing rule. Drupal supports Nginx 1.1 or later on UNIX/Linux, macOS, and Windows, although the PHP-FPM process and service names differ by operating system.

Prerequisites and checks before editing Nginx

  • Administrative access to the Nginx configuration and the ability to reload the service.
  • A working Drupal installation with a known front controller file named index.php.
  • PHP-FPM installed and running, unless PHP is supplied through another FastCGI service.
  • The PHP-FPM Unix socket path or TCP address used by this host.
  • Read access for the Nginx worker to Drupal’s code and write access for PHP-FPM to Drupal’s public-files directory where uploads and generated assets are stored.
  • The correct domain name and, if applicable, the URL prefix under which Drupal is published.

Do not start by copying a block from an unrelated server. Drupal’s project layout, PHP version, distribution packaging, and proxy arrangement determine several paths. First identify the file that should receive front-controller requests, then build the configuration around that file.

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

Find the Drupal web root

The Nginx root must be the directory that contains the index.php used by the public site. In a Composer-based project this is commonly a web directory, such as /var/www/drupal/web, rather than the repository’s top-level directory. A non-Composer installation may place index.php directly in the project directory.

  1. Locate the Drupal installation on disk.
  2. Find the public index.php that belongs to the site, not a test fixture or a file in a vendor directory.
  3. Record its containing directory as the Nginx root.
  4. Confirm that the directory also contains Drupal’s public subdirectories, including the directory used for uploaded and generated files.

If the root points one level too high, Nginx may serve a directory listing, return 404 responses, or expose files that were never intended to be public. If it points too low, static files and the front controller cannot be found.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Use this Nginx configuration pattern

The following server block provides the essential routing and PHP handling. Replace the domain, document root, and PHP-FPM socket with values from your server.

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;
    }
}

The location / rule first serves an existing file. If the requested path is not a file, try_files internally redirects it to /index.php and appends the original query string. Preserving $query_string matters for links and forms that include parameters.

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

The PHP location sends requests ending in .php to PHP-FPM. SCRIPT_FILENAME must resolve to the actual file under the configured root. The sample uses $document_root$fastcgi_script_name; if your deployment uses symlinks or a packaged include, verify that the resulting path still points to the real Drupal file.

Some Linux distributions provide a FastCGI include file containing equivalent parameters. You may use it when it supplies the required script filename and request parameters, but do not assume that an include from another distribution has the same socket path or security defaults.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Install the rule step by step

  1. Identify the active server block. Make sure the domain resolves to the Nginx instance you are editing and that no earlier or more specific server block is handling the request.
  2. Set the web root. Point root to the directory containing Drupal’s public index.php. Set index index.php; so requests for the site root can resolve to the front controller.
  3. Add the front-controller fallback. Inside location /, add try_files $uri /index.php?$query_string;. Do not replace it with a fallback that drops the query string.
  4. Configure PHP-FPM. Add a PHP location, set fastcgi_pass to the actual Unix socket or TCP upstream, and set SCRIPT_FILENAME to the resolved Drupal path.
  5. Check permissions. The Nginx worker must be able to traverse and read the code directories. PHP-FPM must be able to write Drupal’s public-files directory when the site needs uploads, image styles, aggregated assets, or other generated files. Grant only the required permissions; a world-writable tree is not an appropriate fix.
  6. Validate syntax. Run nginx -t. Fix every reported error before reloading the service.
  7. Reload Nginx. On systems managed by systemd, use the service manager’s reload operation, for example sudo systemctl reload nginx. Use the equivalent command for another service manager.
  8. Test a known route. Request /user/login or another route that is known to exist, without adding ?q=. Then test the home page, a node page, an image, a CSS file, and a JavaScript file.

How a successful request flows

  1. The browser requests a path such as /user/login.
  2. Nginx checks whether that path maps to an existing file beneath root.
  3. Because the route is normally not a file, try_files internally redirects it to /index.php while retaining the query string.
  4. The PHP location passes index.php to PHP-FPM.
  5. Drupal bootstraps, resolves the route, checks access, and returns the page.

Static files take a different path: if a CSS file, JavaScript file, image, or favicon exists under the root, Nginx serves it directly and does not invoke Drupal. This distinction explains why a working page can still have broken styling: the front-controller rule may be correct while the files directory, permissions, URL prefix, or static-file handling is wrong.

Choose paths for the deployment layout

Deployment choice What changes What to verify
Domain root The site is served as https://example.com/; the fallback is /index.php?$query_string. The configured root contains the public index.php and the domain’s active server block is selected.
Subdirectory The public site is under a prefix such as /drupal/; root, location matching, front-controller fallback, and Drupal’s path-prefix settings must agree. Test links, forms, CSS, JavaScript, image styles, and redirects with the prefix included. A root-level fallback copied unchanged can send requests to the wrong front controller.
Unix-socket PHP-FPM fastcgi_pass uses a path beginning with unix:. The socket exists, PHP-FPM is running, and the Nginx worker can access the socket.
TCP PHP-FPM upstream fastcgi_pass uses an address such as a local port or an upstream group. The address and port are reachable from Nginx and the upstream accepts the PHP version used by Drupal.
Single site One server block and one Drupal root handle the host. No default server block or duplicate hostname captures requests first.
Multisite Each hostname or site mapping may use a distinct root, settings file, files directory, or server block. Verify that the host reaches the intended root and that a shared fallback does not expose another site’s files.
Direct Nginx termination Nginx receives the client request and serves HTTPS or HTTP directly. Host and scheme are correct at Nginx and Drupal sees the expected request.
Reverse proxy or load balancer Another component may terminate TLS and forward the request to Nginx. Forwarded-host and forwarded-proto handling is configured in both Nginx and Drupal so redirects use the public host and scheme.

PHP-FPM details that affect clean URLs

A rewrite problem and a PHP execution problem often look identical in a browser. A missing PHP location can make /user/login fail after the fallback, even though try_files is correct. Conversely, an incorrect socket can produce a 502 after Nginx has successfully routed the request.

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

Unix sockets

Distribution packages commonly place the socket under a versioned directory, while custom PHP-FPM installations may use a different path. Inspect the PHP-FPM pool configuration or service status rather than guessing. The socket’s ownership and mode must permit the Nginx worker to connect.

TCP upstreams

When PHP-FPM listens on TCP, use the configured address and port. A container, virtual machine, or separate host may require a network name rather than 127.0.0.1. Confirm firewall rules and reachability from the Nginx host.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Script filename resolution

For a request to /index.php, $document_root$fastcgi_script_name should resolve to the same index.php found during the web-root check. If it resolves outside the Drupal directory, PHP may return 404, expose source handling errors, or execute the wrong file. Review the effective Nginx configuration when multiple roots, aliases, or symlinks are involved.

Fix missing CSS, JavaScript, images, and image styles

After the page itself loads, open the browser’s network panel and identify the exact failed asset URL. Then check the same URL in Nginx’s access log. A 404 usually means the URL maps to a missing file, the root is wrong, or Drupal’s public-files path is not where Nginx expects. A 403 points more often to filesystem permissions or an access rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Confirm that the public-files directory exists beneath the configured root or is deliberately mapped to its actual location.
  • Ensure the Nginx worker can read directories and files along the complete path.
  • Ensure PHP-FPM can write where Drupal generates uploads, image styles, or aggregated CSS and JavaScript.
  • Check that a custom static-file location is not intercepting requests that should reach Drupal for generated assets.
  • Look for an incorrect subdirectory prefix in Drupal’s generated URLs.
  • Clear Drupal’s caches only after filesystem paths and permissions are correct; cache clearing cannot repair an Nginx root that points to the wrong directory.

Do not solve asset failures by routing every request to PHP. Existing static files should normally be served by Nginx, and broad PHP routing increases work and can obscure the real path error.

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

Protect Drupal files while enabling routing

The front controller should handle public routes, not make private data or deployment files publicly readable. Keep Drupal’s private files and sensitive directories protected according to the current Drupal security guidance for the installed version. Review any location blocks that deny access to configuration, vendor, backup, or repository files, and test those protections after every configuration change.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Place access restrictions carefully. An overly broad deny rule can block legitimate CSS, JavaScript, or image-style files; an overly narrow rule can expose files that should never be downloaded. Keep code ownership and permissions separate from the public-files write requirement, and avoid granting write access to the entire Drupal tree.

Troubleshooting by symptom

Symptom Checks and corrective action
/user/login returns 404, but /index.php works Inspect the active server block and confirm that location / contains try_files $uri /index.php?$query_string;. Verify that root is the directory containing the intended index.php.
Every route fails except the home page The front-controller fallback is missing, placed in a different server block, or overridden by a more specific location. Run nginx -T when available to inspect the complete active configuration.
CSS, JavaScript, or image styles return 404 Check the public-files path, URL prefix, root, and permissions. Make sure a static-file or alias location is not pointing at a different directory.
PHP source downloads or PHP requests return 404 Check that the PHP location exists, is ordered and matched as intended, uses the correct fastcgi_pass, and sets SCRIPT_FILENAME to the real file.
502 Bad Gateway Check PHP-FPM service status, the socket or TCP address, socket permissions, and Nginx’s error log. A 502 is generally an upstream connectivity or process failure, not a Drupal route definition.
403 Forbidden Inspect filesystem traversal and read permissions, Nginx deny rules, and SELinux or other mandatory-access-control logs where applicable. Do not immediately make the whole tree writable.
Routes work at the domain root but fail in a subdirectory Adapt the location match, root, front-controller fallback, and Drupal path-prefix configuration to the installation’s actual URL base. Test absolute and relative asset URLs as well as redirects.
Login redirects to the wrong host or scheme behind a proxy Review Drupal reverse-proxy and forwarded-header settings together with the proxy and Nginx configuration. Routing alone does not determine the public HTTPS scheme when another service terminates TLS.

Use logs to separate Nginx, PHP, and Drupal failures

Check the Nginx access log for the requested path and status code, then check the Nginx error log for filesystem, permission, and upstream messages. PHP-FPM’s log identifies pool failures, script-not-found errors, and worker exhaustion. Drupal’s own logs can explain route access denial or application exceptions after Nginx and PHP have successfully delivered the request.

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

Correlate timestamps and request paths. If Nginx logs a 404 before an upstream request, the problem is routing or a missing file. If Nginx reports an upstream 502, investigate PHP-FPM. If PHP returns a Drupal error page with a normal HTTP response, the web-server path is probably functioning and the remaining issue is application configuration or permissions.

Reverse-proxy and forwarded-header considerations

When a load balancer or TLS proxy sits in front of Nginx, the internal request may arrive over HTTP even though the visitor used HTTPS. Drupal needs trusted reverse-proxy and forwarded-header settings so it can construct secure redirects and absolute URLs correctly. Configure trust narrowly for the known proxy addresses; accepting arbitrary forwarded headers allows clients to influence host and scheme values.

Test login, password-reset, canonical redirects, and generated asset URLs through the public hostname, not only by connecting directly to the Nginx server. A configuration that works on the internal address can still loop or redirect to the wrong scheme at the edge.

Operational checklist after enabling clean URLs

  • nginx -t succeeds before each reload.
  • The active root contains the intended Drupal index.php.
  • try_files $uri /index.php?$query_string; is present in the server block handling the site.
  • The PHP-FPM socket or upstream is reachable and matches the configured PHP service.
  • SCRIPT_FILENAME resolves to the real Drupal file.
  • The Nginx worker can read code and static assets.
  • PHP-FPM can write the required public-files locations.
  • Home page, login, a content route, CSS, JavaScript, an uploaded image, and an image style have been tested.
  • Logs have been checked for 404, 403, 502, and permission errors.
  • Private files and sensitive directories remain inaccessible from the web.
  • Proxy deployments have been tested through the public scheme and hostname.

When managed Drupal hosting is the better option

Self-managed Nginx is appropriate when you control the server, can maintain PHP-FPM and operating-system security, and need direct control over deployment layout. If you do not have root access or cannot inspect Nginx and PHP-FPM logs, a managed Drupal host may be more practical. In that arrangement, ask support to confirm the public document root, front-controller fallback, PHP-FPM handling, writable files directory, and reverse-proxy settings rather than simply asking them to “turn on clean URLs.”

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

Regardless of who manages the server, the acceptance tests are the same: a known Drupal route must work without ?q=, static assets must load, uploads and generated files must be writable where required, and private paths must remain protected.

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.

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.