Nginx Catch-All Host As Front End To Apache For ISPConfig 3 On Debian
Nginx Catch-All Host As Front End To Apache For ISPConfig 3 On Debian
Author: Nedim Hadzimahmutovic
Version: v1.1
Last Change: May 19, 2010
Introduction
Apache has always been the web server of choice for me. It is a real beast when it comes to resource usage, especially in a resource-limited environment such as a VPS. I started playing with Nginx a lightweight, high-performance web server. My area of interest was running Nginx as a reverse proxy and making it work in a Apache/ISPConfig 3 environment.
The Problem
I am an OpenVZ, apache2-mpm-itk, mod_php user. Apache mpm-itk does not support FastCGI. This problem dramatically increases if you use a 64-bit OS since Apache will now use much more memory (32-bit systems have 4-byte pointers whereas 64-bit systems have 8-byte pointers). I started getting KMEMSIZE limit errors and Apache was the reason why. Apache made my VPS unusable so I had to look for an alternative.
The Solution
Nginx was the answer but I am an ISPConfig user who only supports Apache and if I found a way around this there was no way I would manually manage each virtual host. The solution was to set up “Nginx catch all host” as the front-end and proxy to Apache which will be running in the back-end on a different port. This way Nginx will serve the static files and PHP will be left to Apache. You can also leave a whole domain to Nginx if you like, just put that domain’s virtual host before the default vhost.
One step further would be to run a 32-bit chroot environment on top of the 64-bit OS and install 32-bit Apache but this will not be covered in this tutorial.
Configure Apache
Configure Apache to run on port 82 in /etc/apache2/ports.conf and in all of your virtual hosts. To make it easier use sed command:
I assume your virtual host is IP based - your vhost could have *:80 instead of IP:80.
The sed command will make backup files of your .vhost files which will have .vhoste extension. You can move the backup vhost files:
Restart Apache and use netstat
check if it is running on port 82:
Now you have to change the ISPConfig Apache templates. Copy them to your conf-custom directory:
Open the two files and change :80 to :82. Just to be sure run grep command and check if the output matches:
You will see all requests as originating from localhost (127.0.0.1). To see users real IP address you will have to install libapache2-mod-rpaf:
Add the following to /etc/apache2/apache2.conf:
Installing And Configure Nginx Enable the lenny-backports repository, you will find the instructions on http://backports.org/.
Remove the default vhost:
Open the file:
Add the following content to the file:
or do a proxy_pass to your server’s IP address
Do not forget to replace IP-ADDRESS with your web server’s ip address.
That’s it. Nginx will serve all your static files like images even html files and php stuff will be forwarded to Apache.