stocksy.co.uk
"the site for those who crave disappointment"

Sponsored Links

Apache 2.2.0 (and mod_proxy) on OS X

3rd Dec 2005, 10:58:31

By James Stocks

Apache 2.2.0 was released on Thursday, including some compelling new features.

I needed to recompile to get mod_proxy anyway, so I installed it without delay:

$ sudo apachectl stop
$ cd ~/source
$ curl -O http://www.mirrorservice.org/sites/ftp.apache.org/httpd/httpd-2.2.0.tar.bz2
$ tar xjf httpd-2.2.0.tar.bz2
$ cd httpd-2.2.0
$ ./configure --enable-modules=most --enable-shared=max --enable-ssl --enable-deflate --enable-headers --enable-proxy --disable-dav --prefix=/usr/local/apache2.2
$ make
$ sudo mv /usr/local/apache2 ~/temp
$ sudo make install
$ sudo cp ~/temp/apache2/conf/*.conf /usr/local/apache2/conf/
$ sudo apachectl start

It complained about my PHP module being garbled. I'll have to recompile that then. I still had the source laying around anyway.

$ cd ~/source/php-5.1.1
$ make distclean
$ ./configure --with-xml --with-zlib --with-gd --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local --with-png-dir=/usr/local --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs
$ make
$ sudo make install

PHP likes to duplicate the LoadModule php5_module modules/libphp5.so line in my httpd.conf, so I removed it.

$ sudo apachectl start

Now Apache starts fine.

Reverse Proxying with mod_proxy

I have just a single public IP address, but several computers. My Power Mac acts as my main Web server, so tcp port 80 is in use. I wanted to use Apache on my toaster (running Debian Sarge), so I had a choice: Run the toaster's httpd on a port other than 80, or do something clever. Since weird ports are not accessible through the proxy at my place of work, this was not a difficult choice.

My Reverse Proxy Setup

On the Power Mac

$ sudo vi /usr/local/apache2/httpd.conf

(or whatever)

Assuming you have a NameVirtualHost *:80 entry, Insert:

<VirtualHost *:80>
ServerName test.toastputer.net
##Set this to be OFF or you will be an OPEN PROXY
##and BAD THINGS WILL HAPPEN:
ProxyRequests off
ProxyPass / http://test.toastputer.net
ProxyPassReverse / http://test.toastputer.net/
</VirtualHost>

Tell the Power Mac where to find test.toastputer.net - not needed if you have a proper DNS setup.

$ sudo -s
# echo "172.16.0.15 test.toastputer.net" >> /etc/hosts
# apachectl restart

On the Toaster

$ su -
# vi /etc/apache2/sites-available/test
<VirtualHost *>
DocumentRoot /var/www/test
ServerName test.toastputer.net
</VirtualHost>

# ln -s /etc/apache2/sites-available/test /etc/apache2/sites-enabled/test
# mkdir /var/www/test
# echo "Some rubbish..." > /var/www/test/index.html
# /etc/init.d/apache2 restart

And Finally

Test it! Preferably from an external IP address. If you examine the response from the server, you can see it identifies itself as Apache on Linux.

stocksy@sl23020:~$ telnet test.toastputer.net 80
Trying 194.106.52.245...
Connected to test.toastputer.net.
Escape character is '^]'.
GET / HTTP/1.1
Host: test.toastputer.net
HTTP/1.1 200 OK
Date: Sat, 03 Dec 2005 12:44:44 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.3.10-16
X-Powered-By: PHP/4.3.10-16
Content-Type: text/html
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked

This seems to confuse things like netcraft, which will report "Apache (Debian GNU/Linux) on Mac OS X" :-)

mod_cache sounds like a great counterpart to mod_proxy, maybe I'll look into that later.

New Comments

Some Rights Reserved