This is the third of several articles concerning our system architecture. It’s primarily aimed at technically minded ladies and dudes. But don’t feel left out if you didn’t read the first or second articles! They’re right here: Site Architecture: Servers and Site Architecture: Software.
Read ‘em and come back, because today we’re talking about Apache httpd!
Just to recap: We have a couple of servers hosted in a cloud-like environment. We’re running Apache httpd, MySql, PHP, memcached and a couple of other daemons.
Today’s article isn’t at all that earth shattering. I’m just laying some foundations for future articles. Caveat lector.
We built and deployed Apache httpd like so:
1 2 3 4 5 6 7 8 |
:~$ wget httpd-2.2.10.tar.gz :~/httpd-2.2.10$ tar xzf httpd-2.2.10.tar.gz; cd httpd-2.2.10 :~/httpd-2.2.10$ ./configure --enable-rewrite=shared \ --enable-module=so \ --enable-proxy \ --enable-proxy-connect \ --enable-proxy-http :~/httpd-2.2.10$ make; sudo make install |
By default it put our httpd directory under /usr/local/apache2.
We’re (theoretically) configured in such a way that – should the need arise – we can theoretically start up another server instance running nginx, theoretically duplicate our master httpd instance, do a little magic and presto-chango, the nginx instance should theoretically load balance (theoretically) across two or more httpd servers.
Our nginx config looks something like this (not exact, so don’t just copy and paste it… it won’t work!):
1 2 3 4 5 6 7 8 9 10 11 |
http {
upstream stoopad {
server 192.168.0.1:80;
...
}
server {
listen 80;
server_name stoopad.com;
location / {
proxy_pass http://stoopad;
} } }
|
… While our httpd.conf files are pretty vanilla. We make heavy use of mod_rewrite and mod_proxy (for items not discussed here). Stoopad.com, for instance, looks a lot like this (remember: Don’t just copy and paste, I’ve left out essential configuration options for brevity’s sake):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<VirtualHost *:80>
ServerName stoopad.com
ServerAlias www.stoopad.com
DocumentRoot /var/apache/stoopad
<Directory />
Order deny,allow
Deny from all
</Directory>
CustomLog /var/logs/stoopad/access_log combined
</VirtualHost>
<VirtualHost *:80>
ServerName forums.stoopad.com
DocumentRoot /var/apache/stoopadforums
<Directory />
Order deny,allow
Deny from all
</Directory>
CustomLog /var/logs/stoopadforums/access_log combined
</VirtualHost>
|
Notice we’re using named virtual hosts! That’s ’cause ours isn’t the only site hosted on our web server, and that’s okay: We’re relatively tiny and can afford to share our bandwidth.
Only httpd is started on machine boot. On most days, we have no reason to launch an instance of nginx, so it just sits around twiddling its thumbs, waiting for the big day when it can also be a big player in our cloud. But until that day, we have httpd, and that suits us just fine.
Do you use nginx? httpd? Starbucks or McDonalds coffee??
