NGINX & WordPress 404 error on permalinks (ALMA 8/9 & Directadmin)

Categories: Directadmin, Linux

Permalinks not working — 404 error

If you’re experiencing 404 errors when trying to access permalinks on your blog, it might be due to a misconfiguration with your server settings. This is a common issue for those using Alma 8/9, Nginx, and DirectAdmin. Fortunately, the solution is fairly straightforward.

Prerequisites:

  • Operating System: Alma 8/9
  • Web Server: Nginx
  • Control Panel: Directadmin

Step-by-step Solution:

  1. Locate the Configuration File:
  2. Navigate to the nginx configuration file for the specific user. This is usually located in:
  3. /usr/local/directadmin/data/users/username
  4. Replace username with the appropriate username for the account in question.
  5. Edit the Configuration:
  6. Within the configuration file, you will need to locate the server block(s). You might have multiple blocks, especially if your site is set up for both HTTP and HTTPS.
  7. Add the following line inside each server block:
  8. try_files $uri $uri/ /index.php?$uri&$args;
  9. Here is an example of what it might look like for both HTTP (port 80) and HTTPS (port 443):
  10. server { listen hosting-ipaddress:80; … try_files $uri $uri/ /index.php?$uri&$args; … } server { listen hosting-ipaddress:443 ssl http2; … try_files $uri $uri/ /index.php?$uri&$args; … }
  11. Ensure you replace hosting-ipaddress with the actual IP address of your hosting server.
  12. Save and Restart:
  13. After making the necessary changes, save the configuration file and restart the Nginx service to apply the changes.

Important Notes:

  • Always make sure to backup your configuration files before making any changes.
  • If you’re unfamiliar with editing Nginx configurations, it’s recommended to seek assistance from a knowledgeable colleague or professional.
  • The provided solution ensures that Nginx correctly processes permalinks by passing requests to the appropriate PHP file with the necessary arguments. This ensures that you don’t run into 404 errors when accessing permalinks.

We hope this guide assists you in resolving the 404 permalink error on your blog. If you have further questions or run into any issues, please reach out in the comment for additional support. Safe blogging!

Permanent solution: Modifying Nginx Template in DirectAdmin

1. Copy the template:

Copy the template from its current location to the custom directory using the following command: cp /usr/local/directadmin/data/templates/nginx_server* /usr/local/directadmin/data/templates/custom/

2. Modify the template:

You can modify the template using a text editor like nano, vim, or emacs. Here’s how you can do it using nano: nano /usr/local/directadmin/data/templates/custom/nginx_server*

This command opens the file in nano. After making your desired modifications, save and exit. In nano, use CTRL + O to save and CTRL + X to exit.

3. Run rewrite_confs:

After making modifications, let DirectAdmin recognize and apply the changes by running the following command: /usr/local/directadmin/scripts/rewrite_confs

Note: Ensure you have backups of any important data or configurations before making changes. Always test new configurations in a safe environment before applying them to a live server.

«
»

    Leave a Reply

    Your email address will not be published. Required fields are marked *