NGINX Reverse Proxy Apache on DirectAdmin

The following article is dealing with the most common problems you can come across, if you decide to switch from Apache- only LAMP server to Apache+NGINX driven one.

Nginx (pronounced engine x) has been around for more than a decade. NGINX is a HTTP and reverse proxy server. It has proved its advantages over Apache in many setups:

  • Nginx works faster when serving high volume of requests
  • Nginx doesn’t spawn new process or thread for each request. Hence it consumes less memory and works much better with high volume of request.
  • Nginx is efficient at serving of static content. It has low memory usage, but consumes more processor time compared to Apache.
  • It is a great solution for dedicated and virtual private servers, where you don’t need Apache .htaccess ability.

In order to get the best of the both servers, we have NGINX serve static assets while Apache processes the dynamic content.

CustomBuild2.X Prerequisive

The new Custombuild2.x versions allows for an easy and quick installation of Apache + NGINX as a reverse proxy server. The only prerequisite for this to work is CustomBuild2.x. As 2.x version was released in 2006, the chances are that your intallation have it by the year of 2019.
In case you want to check CustomBuild version:

cd /usr/local/directadmin/custombuild
./build version

The command above should produce a results similar to the one below:
[root@myserver custombuild]# ./build version
2.0.0 (rev: 2084)

Also check the version of Directadmin. It should be 1.45.2 or later:

/usr/local/directadmin/directadmin v
Version: DirectAdmin v.1.56.4

If you need to update software in DirectAdmin you can follow the steps provided in one of my previous posts. If you have made any changes to Apache or any other software which is installed/updated with cusombuild, they will be overwritten. As you don’t want the changes to be lost, use the official way for customization, creating a custom directory in /usr/local/directadmin/custombuild

Make sure you are in the right directory
cd /usr/local/directadmin/custombuild
mkdir -p custom
cp -Rp configure custom

After that you can edit your configs as needed.

Once you are ready with all the customizations, the following commands will help you switch to apache+nginx (apache in front of apache as a reverse proxy) cd /usr/local/directadmin/custombuild
./build update
./build set webserver nginx_apache
./build nginx_apache
./build rewrite_confs

The last command will up rewrite all configuration files, if they are not in the custom directory

Also, after the installing the proxy, it is possible that nginx reverse proxy will not show the images. NGINX serves all the static assets of the website while the user nginx doesn’t have read and execute rights at the website webroot directory. This is easily fixed if you give the user nginx rights to enter +x and read +r the files in the public_html directory:
chmod 755 -R public_html
. Have fun with your new installation.

Diana D has written 25 articles

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>