Switching from Apache to Nginx on Webuzo Broke Your Permalinks? Here Is the Exact 404 Fix

Switching from Apache to Nginx on Webuzo Broke Your Permalinks? Here Is the Exact 404 Fix

By Reggi, 29 Dec 2022

You just flipped the web server switch in your Webuzo VPS panel from Apache to Nginx, expecting a performance boost. Instead, every custom permalink, slug, and sub-path on your website collapses into a wall of 404 Not Found: The requested URL was not found on this server.

When you transition an environment managed by Webuzo to Nginx, existing URL routing rules that relied on Apache do not translate out of the box. Nginx processes requested URIs directly against the disk. Without an explicit fallback mechanism to pass unhandled slugs back to your application handler, Nginx throws an immediate 404 error.

Fixing this routing failure requires injecting a single directive block into the shared Nginx configuration file on your server.

Targeting the Nginx Common Configuration

To resolve the issue across your domains on the server, you need to append a fallback routing block directly inside the central common configuration file.

Connect to your VPS environment via SSH using a terminal emulator like PuTTY, or open a connection using an SFTP client. The target file is located at:

bash
/usr/local/apps/nginx/etc/conf.d/common

Modifying files in this directory requires administrative privileges. If you are not operating as root, prefix your commands with sudo.

To edit the file with Vim:

bash
sudo vim /usr/local/apps/nginx/etc/conf.d/common

Inside Vim, hit the i key to switch into insert mode.

If you prefer Nano, run:

bash
sudo nano /usr/local/apps/nginx/etc/conf.d/common

Injecting the URI Fallback Directive

Navigate directly to the very end of the file. Do not edit, modify, or delete any existing lines already present in the configuration.

Append the following location block to the bottom of the file:

nginx
location / { try_files $uri $uri/ /index.php?q=$request_uri; }

This directive tells Nginx to evaluate the requested URI in a specific sequence:

  1. $uri: Check if a static file matching the exact URI exists.
  2. $uri/: Check if a directory matching the URI exists.
  3. /index.php?q=$request_uri: If neither a file nor a directory exists, route the entire request string to /index.php as a query parameter (q=$request_uri).

Saving Changes and Reloading Nginx

Once the configuration block is appended to the bottom of the file, save your changes and exit your editor.

For Vim:

  1. Press the Esc key to exit insert mode.
  2. Type :wq! and hit Enter to write the file and quit.

For Nano:

  1. Press Ctrl-X.
  2. Press y to confirm saving the buffer, then hit Enter.

The changes will not take effect until Nginx reloads its configuration. You can apply the new setup using either the command line or the Webuzo graphical control panel.

Method 1: Command Line Restart

Run the following service command in your terminal:

bash
service nginx restart

Method 2: Webuzo Panel Interface

If you prefer managing services via the browser interface:

  1. Log in to your Webuzo panel.
  2. Navigate to the Services menu.
  3. Locate nginx in the service list.
  4. Click the reload/refresh icon.

Once the Nginx service reloads, all custom slugs and URLs on your website will resolve normally without throwing 404 errors.


Popular Reads