Apache: VirtualHost with [PHP|Python|Ruby] support
-
23-08-2019 - |
Question
I am experimenting with several languages (Python, Ruby...), and I would like to know if there is a way to optimize my Apache Server to load certain modules only in certain VirtualHost, for instance:
http://myapp1 <- just with Ruby support
http://myapp2 <- just with Python support
http://myapp3 <- just with Php support
...
Thanks.
Solution
Each Apache worker loads every module, so it's not possible to do within Apache itself.
What you need to do is move your language modules to processes external to Apache workers.
This is done for your languages with the following modules:
- PHP: mod_fastcgi. More info: Apache+Chroot+FastCGI.
- Python: mod_wsgi in daemon mode.
- Ruby: passenger/mod_rack
OTHER TIPS
I dont think thats possible as,
- The same thread/forked process might be serving pages from different Virtualhosts. So if it has loaded only python, what happens when it needs to serve ruby?
- For reason 1, certain directives are web server only, and not virtualhost specific. MaxRequestsPerChild, LoadModule etc are such.
I think the only way is to have a "proxy" web server that dispatches requests to the real servers ...
The proxy server has a list of domain names -> Server Side language, and does nothing else but transparently redirecting to the correct real server
There are N real server, each one with a specific configuration and a single language supported and loaded ... each server will listen on a different port of course and eventually only on the loopback device
Apache mod_proxy should do the job
My 2 cents
My Idea is several apache processes (each one with different config) listening on different addresses and/or ports and a http proxy (squid or apache) in the front redirecting to respective server. This has a possible added advantage of caching.