How to Set Up Nginx on Your DirectAdmin Server
This guide will show you how to set up Nginx on a server running DirectAdmin. You can configure Nginx in two main ways. You can use it as a standalone web server, which replaces Apache. Or, you can use it as a reverse proxy in front of Apache, which often improves performance.
Important Note: Before you start, it is a very good idea to create a full backup of your server. Changing your web server can affect all the websites you host.
Part 1: Setting Up Nginx as a Standalone Web Server (Replacing Apache)
In this setup, Nginx handles all web requests directly. Apache will be shut down and will not be used.
- Access DirectAdmin as Admin
- Log in to your DirectAdmin control panel with administrator privileges.
- Navigate to the “Admin Level” section.
- Install Nginx Using CustomBuild
- Click on “CustomBuild 2.0” in the Admin Level menu.
- In CustomBuild, click on the “Web Server” section.
- From the dropdown menu, select “nginx” as your web server.
- Ensure “nginx” is selected in the “Web Server Settings” section.
- Click “Update” to save the changes.
- Build and Install Nginx
- Go back to the main CustomBuild screen.
- Click on “Build” or “Update” options.
- Select “nginx” from the software list to build.
- Click “Start” to begin the compilation and installation process.
- Wait for the process to complete. This may take several minutes.
- Stop Apache Service
- In DirectAdmin, go to “Service Monitor” in the Admin Level.
- Find the “httpd” (Apache) service.
- Click “Stop” to shut down Apache.
- Ensure Apache is set to not start automatically on reboot.
- Start Nginx Service
- In the same “Service Monitor” page.
- Find the “nginx” service.
- Click “Start” to launch Nginx.
- Ensure Nginx is set to start automatically on system boot.
Your server is now running Nginx as its sole web server. All your DirectAdmin accounts and websites will be served by Nginx.
Part 2: Setting Up Nginx as a Reverse Proxy for Apache
This setup uses Nginx in front of Apache. Nginx handles static files directly and passes dynamic requests to Apache.
- Access DirectAdmin as Admin
- Log in to your DirectAdmin control panel with administrator privileges.
- Navigate to the “Admin Level” section.
- Configure Nginx as Reverse Proxy
- Click on “CustomBuild 2.0” in the Admin Level menu.
- In CustomBuild, click on the “Web Server” section.
- From the dropdown menu, select “nginx_apache” as your web server.
- Ensure “nginx_apache” is selected in the “Web Server Settings” section.
- Click “Update” to save the configuration.
- Build and Install Both Services
- Go back to the main CustomBuild screen.
- Click on “Build” or “Update” options.
- Select both “nginx” and “apache” from the software list.
- Click “Start” to begin the compilation and installation.
- Wait for the process to complete.
- Configure Services
- Go to “Service Monitor” in the Admin Level.
- Ensure both “nginx” and “httpd” services are running.
- Set both services to start automatically on system boot.
- The correct startup order is handled automatically by DirectAdmin.
In this setup, visitors connect to Nginx. Nginx then works as a proxy:
- If a request is for a static file, Nginx serves it directly and very quickly.
- If a request is for a dynamic page (like a PHP script), Nginx passes it to Apache in the background.
- Apache processes the PHP and generates the page, then sends it back to Nginx.
- Nginx finally delivers the page to the visitor.
Final Steps and Verification
After completing either setup, you must test your work.
- Check Your Website
Open your website in a web browser. It should load normally. You can also open it in a private/incognito window to avoid seeing a cached version. - Verify the Server Header Using Command Line
To confirm Nginx is working, you can check the HTTP headers of your site using command line tools. Using curl command:- Open your terminal or SSH connection to your server or any Linux/macOS computer.
- Run this curl command:
curl -I http://yourdomain.comReplaceyourdomain.comwith your actual domain name. - Analyze the output. Look for the “Server” header in the results: Example output for Nginx Standalone:
HTTP/1.1 200 OK Server: nginx Date: Wed, 01 Jan 2025 12:00:00 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-aliveExample output for Nginx Reverse Proxy:
You might see one of these patterns: Pattern 1: Nginx header visibleHTTP/1.1 200 OK Server: nginxPattern 2: Apache header visible (but Nginx is still working)HTTP/1.1 200 OK Server: Apache
- If you see
Server: nginx, Nginx is definitely active and serving your requests. - If you see
Server: Apachewhile in Reverse Proxy mode, this is normal. The request is still going through Nginx first, but Apache is adding its own header. The performance benefits are still working.
curl -L -I -v http://yourdomain.comThis will show you all the redirects and very verbose header information. - Additional DirectAdmin Configuration
- For individual user settings, you can modify Nginx configuration through the “User Level” in DirectAdmin.
- Custom Nginx configurations can be added in the “Custom HTTPD Configurations” section.
- Monitor server resources through DirectAdmin’s “Admin Level” to ensure optimal performance.
By following these steps, you can successfully integrate the speed and efficiency of Nginx with your DirectAdmin server, either as a powerful replacement for Apache or as a performance boosting partner for it.
