/

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.

  1. Access DirectAdmin as Admin
    1. Log in to your DirectAdmin control panel with administrator privileges.
    2. Navigate to the “Admin Level” section.
  2. Install Nginx Using CustomBuild
    1. Click on “CustomBuild 2.0” in the Admin Level menu.
    2. In CustomBuild, click on the “Web Server” section.
    3. From the dropdown menu, select “nginx” as your web server.
    4. Ensure “nginx” is selected in the “Web Server Settings” section.
    5. Click “Update” to save the changes.
  3. Build and Install Nginx
    1. Go back to the main CustomBuild screen.
    2. Click on “Build” or “Update” options.
    3. Select “nginx” from the software list to build.
    4. Click “Start” to begin the compilation and installation process.
    5. Wait for the process to complete. This may take several minutes.
  4. Stop Apache Service
    1. In DirectAdmin, go to “Service Monitor” in the Admin Level.
    2. Find the “httpd” (Apache) service.
    3. Click “Stop” to shut down Apache.
    4. Ensure Apache is set to not start automatically on reboot.
  5. Start Nginx Service
    1. In the same “Service Monitor” page.
    2. Find the “nginx” service.
    3. Click “Start” to launch Nginx.
    4. 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.

  1. Access DirectAdmin as Admin
    1. Log in to your DirectAdmin control panel with administrator privileges.
    2. Navigate to the “Admin Level” section.
  2. Configure Nginx as Reverse Proxy
    1. Click on “CustomBuild 2.0” in the Admin Level menu.
    2. In CustomBuild, click on the “Web Server” section.
    3. From the dropdown menu, select “nginx_apache” as your web server.
    4. Ensure “nginx_apache” is selected in the “Web Server Settings” section.
    5. Click “Update” to save the configuration.
  3. Build and Install Both Services
    1. Go back to the main CustomBuild screen.
    2. Click on “Build” or “Update” options.
    3. Select both “nginx” and “apache” from the software list.
    4. Click “Start” to begin the compilation and installation.
    5. Wait for the process to complete.
  4. Configure Services
    1. Go to “Service Monitor” in the Admin Level.
    2. Ensure both “nginx” and “httpd” services are running.
    3. Set both services to start automatically on system boot.
    4. 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.

  1. 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.
  2. 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:
    1. Open your terminal or SSH connection to your server or any Linux/macOS computer.
    2. Run this curl command: curl -I http://yourdomain.com Replace yourdomain.com with your actual domain name.
    3. 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-alive Example output for Nginx Reverse Proxy:
      You might see one of these patterns: Pattern 1: Nginx header visible HTTP/1.1 200 OK Server: nginx Pattern 2: Apache header visible (but Nginx is still working) HTTP/1.1 200 OK Server: Apache
    What the results mean:
    • If you see Server: nginx, Nginx is definitely active and serving your requests.
    • If you see Server: Apache while 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.
    Alternative method for more detailed headers: For even more detailed information, use this command: curl -L -I -v http://yourdomain.com This will show you all the redirects and very verbose header information.
  3. 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.