It’s no secret that I love using the Directadmin control panel. The interface is very simplistic, and can be archaic at times, but it is very stable, fast, and extremely customization when using the Custombuild 2.0 scripts. Recently, I did just that to deploy Nginx as the back-end web server, instead of the default, which is Apache. Nginx is very fast and performs very well under heavy loads. After migrating serenity-networks.com over, I quickly noticed that none of my links are working. Because I use WordPress, I instantly knew it had something to do with .htaccess or permalinks. The first thing I did was set permalinks to default, and everything started working again. Nginx does not use, nor recognize .htaccess files, which are imperative to URL rewriting, and therefore permalinks. So, I had to figure out how to solve this issue using configuration parameters in the Nginx.conf file. But, this isn’t very straightforward with Directadmin. Here is how to do it.
How to get URL rewrites and WordPress permalinks working with Directadmin, Custombuild 2.0, and Nginx:
The first thing you need to know is how Directadmin handles Nginx configuration files. This is pretty simple. It’s done on a per user bases, and the configuration files are located in /usr/local/directadmin/data/users/username/nginx.conf. Pretty simple. Each username has a folder, and within that folder is an nginx.conf file. This is where you can set parameters per user and even drill down to a specific site for a user. So, the first thing we will do is go to that directory, and edit the appropriate nginx.conf file for your user.
Look for the username for your user and cd into that directory. If you do an ls, you will see many different files.
Go ahead and use nano, or you favorite text editor, to edit the nginx.conf file. Locate the correct site within the configuration file by paying attention to the server_name variable. All you will need to do is simply add a single line, before the closing “}” for your particular site. This is the command:
try_files $uri $uri/ /index.php?$uri&$args;
Be sure to get the semi-colon on the end, it’s important. Here is what my nginx.conf file looked like after adding the appropriate line:
Once you have made the changes, go ahead and save/close. In nano, this is done with a Ctrl-C, then a Y. If you get a permission denied error, you need to exit and use sudo to edit the file. After saving and exiting to the command line, go ahead and restart nginx so the changes go into effect.
# service nginx restart
Now, re-enable permalinks on your WordPress site and you should now have WordPress Permalinks rewriting URLs properly on your Directadmin / Nginx server. If you have any questions, feel free to post in the comments. Thanks!