Configure Nginx to proxy virtual hosts to Apache

Solution? Use nginx as a proxy in front of Apache. Match any static files with an nginx location directive and serve them directly. Pass all other requests to Apache.

Example configurations

We start with Apache and make it listen on a port other than 80 and only on the local address (so no one can access it directly from outside):

You do not need to have your static files in a separate directory. You can also use regular expressions to match static file extensions:

In addition to the proxy_pass directive, other directives allow you to pass various information about the original request to the upstream server for logging purposes or similar. Refer to the nginx documentation for the proxy module.

What about Apache name-based virtual hosts?

Since Apache sees  requests as emanating from nginx, you  need to use the proxy_set_header directive in nginx's config to tell Apache about which hostname was requested originally. You  need an nginx virtual host corresponding to every Apache virtual host to match every incoming request and pass down a the appropriate hostname. For example, if you have this in your httpd.conf:

server { server_name; proxy_pass; proxy_set_header Host $host; }

Now you can enjoy the speed of nginx without translating every Apache configuration directive, and you can also let Apache manage the interpreter for the dynamic language of your choice.