Ubuntu, lighttpd reverse proxy to apache python for django

Not Complete This is a brief note I will update over time to reflect my current setup for serving django with lighty proxying requests.

Benifits of proxying

The benefits of proxying web-requests has been well documented in recent times. Lower over head for serving static files like html, javascript, css and images. In my convoluted setup I am using lighttpd to serve most of my static content which is far faster than using apache with the inherent overhead of python and php and other modules every time a file is requested.

Install the needed software sudo apt-get update sudo apt-get upgrade sudo apt-get install apache2-mpm-worker apache2-threaded-dev lighttpd libapache2-mod-python

Apache Configuration

I have configured apache to listen on port 81 and blocked it from pubic access at the firewall because I will be using lighttpd to proxy requests to apache . I also have disabled apache logging as it will be handled by lighttpd.

Virtual Host <VirtualHost *:81> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /home/websites/example.com/myapp <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE myapp.settings PythonPath "['/home/websites/example.com/']+sys.path" PythonDebug Off </Location> </VirtualHost>

Lighttpd Configuration

Modules for lighttpd server.modules += ( "mod_proxy","mod_rewrite", "mod_fastcgi", "mod_status","mod_cgi", "mod_redirect" )

The static lighttpd server $HTTP["host"] == "media.example.com" { server.document-root = "/home/websites/example.com/media_root" server.errorlog = "/home/websites/example.com/logs/media-error.log" accesslog.filename = "/home/websites/example.com/logs/media-access.log" }

The proxy entry else $HTTP["host"] =~ "(^|\.)example\.com$" { proxy.server = ( "" => ( ( "host" => "127.0.0.1","port" => 81 ))) server.errorlog = "/home/websites/example.com/logs/proxy-error.log" accesslog.filename = "/home/websites/example.com/logs/proxy-access.log" }

Blog

I have finaly took the time to setup a blog, Now the process of theming and adding some… what I hope to be useful guides/notes, examples, and some pointless rants and ravings.

dd tips and tricks

Some tips on using dd for general image creation for emebedded devices

These are just bits and pieces I find worth writing down, more than likely because I keep forgetting them …

create a file with random contents 10kB in size. dd if=/dev/urandom of=/tmp/random.txt bs=10kB count=1

SSH socks proxy

SSH socks proxy

Why would you need to use this , well if you need to check your online banking or purchase tickets etc… from a public network say an airport or a cafe this can securly connect you to your own home/work network.

Note this is not secure in the sense that all requests are just forwarded through to the remote connection and will be visible at that end so to speak…

First we need to create a remote connection from our ‘client’ to our remote server.

To do this in a secure manor for our computer only we would issue the following command substituting our credentials for <user> and our remote ip or domain for <remote.tld> we also specify the localhost:<port> here to only bind to our <port> on the loopback interface so no one on our local network can use this proxy.

ssh -D localhost:<port> <user>@<remote.tld>


Configure Firefox Preferences

Open up firefox preferences

firefox settings

Firefox settings part2


We need to update our configuration to use manual proxy settings and fill in the fields for Socks Host and Port with the values we used above localhost & <port>. You can also add your local device ips to the “No proxy for” list

SSH mount remote file system

Quick note on how to create a sshfs mount to a remote server

Install needed software

sudo apt-get install sshfs

Add your user to the fuse group

sudo adduser $username fuse

Now we need to make a directory (not needed any folder wil do be careful tho)

mkdir ~/Desktop/Remote_Server

Now mount the remote filesystem to the local mount point.

sshfs domain.com:/path/to/folder/on/server ~/Desktop/Remote_Server