Entries Tagged 'linux' ↓

how to setup pinax with nginx

Tonight I spent sometime getting PinaxDjango swiss army knife – to work on nginx via fastcgi on my Ubuntu 9.10 box. Here is a step by step guide.

First of course we need to install nginx, pretty easy with Ubuntu:

sudo apt-get install nginx

Create a new file called <appname> in /etc/nginx/sites-available/ like the following:

upstream djangoserv {
    server 127.0.0.1:8801;
}

server {
    listen   80;
    server_name  alkemic;

    access_log  /var/log/nginx/appname.access.log;

    location ^~ /site_media/  {
        alias /home/nick/dev/projects/pinax07/appname/site_media/;
        autoindex on;
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)   {
        #access_log   off;
        expires      30d;
    }

    location / {
        # host and port to fastcgi server
        fastcgi_pass 127.0.0.1:8801;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
    }
}

Link it to sites-enabled so that we know it’s going to be started up (meanwhile you want to remove the default one):

sudo ln -s /etc/nginx/sites-available/appname /etc/nginx/sites-enabled/

Startup nginx with:

sudo /etc/init.d/nginx start

Activate your pinax installation (change the path to where you have installed your Pinax virtual environment):

source /home/nick/dev/projects/pinax07/bin/activate

Install flup (required to have manage.py run as fastcgi) in your virtual env:

pip install flup

Symlink all the static assets into the site_media folder:

css -> /home/nick/dev/projects/pinax07/appname/media/css/
img -> /home/nick/dev/projects/pinax07/appname/media/img
js -> /home/nick/dev/projects/pinax07/appname/media/js
pinax -> ../../lib/python2.6/site-packages/pinax/media/default/pinax/
snd -> /home/nick/dev/projects/pinax07/appname/media/snd
swf -> /home/nick/dev/projects/pinax07/appname/media/swf

Launch the python fastcgi process:

python ./manage.py runfcgi method=threaded host=127.0.0.1 port=8801

Or:

python ./manage.py runfcgi method=prefork host=127.0.0.1 port=8801

Note that you might need to move your development environment to use a proper db like MySQL because otherwise the app will have problems finding your sqlite db file.

You should have now your app running on the blazing fast nginx.

my desktop during an intense coding session using xmonad

Here is what a coding session of mine looks like when I am in full swing. This is specifically the coding screen. That’s a 1920×1600 resolution screen-shot :D . I obviously also have a browsing screen not shown.

coding session using xmonad

In the image above I am immersed into integrating Compass into Pinax (full post on that will follow).

When developing under Linux (Ubuntu 9.04 at the moment) I have settled for a long time now on the ultra-productive tiling window manager Xmonad. Nothing I tried beats it. My fingers and my brain now are one with the keyboard short-cuts and the concept of mouse-less zen.

Yes I use vim extensively and yes I use screen with the new ubuntu screen-profiles. It rocks.

idea for a useful tool for a web entrepreneur/developer

This is the scenario I was thinking about: I want to interact with a graphic designer remotely, who is very very good with Photoshop and HTML/CSS but who might have trouble setting up the Linux environment needed to run my web app.

What I would like to build (or find if it already exists) is a custom CD that when inserted into a Windows or Mac OSX box does the following:

  • Start a virtualbox/vmware instance with my Linux distribution of choice.
  • Inside the virtual machine the web app is started automatically in debug mode.
  • Proper networking is in place so that the web app is accessible to the host operating system on a specified port.
  • The template/media folder of my web app is shared via SMB with the host OS.

This way the graphic designer could work on the templates/design of the application having (almost) zero knowledge of the technology behind and no access to the code.

I have already developed a solution like this for myself using colinux. But the process required quite some fiddling and was all but automatic. :D

Automated is the keyword.

That’s it.

linux one liner to extract email addresses from a django log file

Say something bad happened and your application sent emails that it shouldn’t have (ahem who? not me…) and you want to collect the emails to apologise. So you just copied the output of a log file in a text file (wrong.txt) like the following:


sending message 'Confirm email address for example.com' to email1@test1.com
sending message 'Confirm email address for example.com' to email2@test2.com
[...]
sending message 'Confirm email address for example.com' to email3@test3.com

Unix command line tools can make the job of extracting those emails and make them ready to be used in a To (or BCC) field a one liner:

cat wrong.txt | awk {'print $9'} | uniq | xargs -I{} echo -n "{},"

The result is:

email1@test1.com, email2@test2.com, [...], email3@test3.com