I have an "archive" server for old sites that no longer are being used, but I want to keep them online as part of my CV/Portfolio.
They require different apache and php versions and setups, so I am running multiple apaches on different ports, behind a nginx reverse proxy.
However, it is not very often that those sites have visitors. It might take days or even weeks between the visits, so I think it is a big wast of memory and cpu to have all those apache instances running all the time.
What I would like to do is to make nginx start the appropriate apache server on demand. Maybe something like this:
- Incoming http request to nginx.
- nginx checks if an apache server is responding on it's tcp port.
- If apache is not responding: run some script to start apache.
- When apache starts responding, reverse proxy the http request to apache.
I want the apache daemon to be loaded with PHP as module. I want the experience to be fast and good when a visiter is surfing the sites, however, a couple of seconds of loading time on the first request is no problem. Some of the sites are very AJAX intensive, so loading apache for every request is not an option.
I do not find any obvious way to do this. Does anyone have any ideas or experiences on a similar setup? Are there other reverse proxy softwares (than nginx) that would do this?
(Of course, I would also need a way to shut down apache on inactivity, but that is quite simple with a cron job just checking if something has happend in apache's access.log.)
Btw.. The server is running Debian Lenny.
Edit / my solution:
I solved this problem by scripting with https://github.com/nodejitsu/node-http-proxy for node.js.
// I'm using http-proxy to make the proxying:
var server = httpProxy.createServer(function (req, res, proxy) {
var domain = getDomain(req);
proxy.proxyRequest(req, res, {
host: '127.0.0.1',
port: configuration[domain].port
});
}).listen(80);
// And a error handler, which will start apache on deman:
server.proxy.on('proxyError', function(err, req, res) {
if (err.errno == 'ECONNREFUSED') {
// Start apache using exec()
}
});
MinSpareServers
andMaxSpareServers
if you want to minimize the number of idle child processes running.Varnish