Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • Running django with daemontools

    Running django fastcgi with daemontools is rather easy but getting it to run in the foreground with the proper user takes a bit of knowledge about how bash works and the tools in daemontools.

    In order to run the fastcgi daemon in the foreground you need to specify the daemonize=false option to the fastcgi command.

    Next the daemon will be started as the root user unless the daemon has an option to change the user itself. The fastcgi daemon doesn't so we will use a tool from daemontools called setuidgid to set the user to www which is the user we want to run the daemon as.

    Finally since we are using setuidgid we need to use the exec command in bash so that the standard process pipe established with the fastcgi process.

    /service/myapp/run

    #!/bin/bash
    
    BASEDIR="/home/www/"
    PIDFILE="$BASEDIR/app.pid"
    
    exec setuidgid www python /home/www/django-prj/manage.py runfcgi \
        --settings=settings_production method=threaded  port=8001 \
        pidfile=$PIDFILE daemonize=false 2>&1
    
    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - Running django with daemontools
  • Django and nginx settings

    One problem I keep encountering with setting up fastcgi with Django is that the default nginx fastcgi parameters cause django to load the top url no matter what url you try to go to. This is because the default nginx fastcgi parameters pass the SCRIPT_NAME parameter to the django instance which Django interprets incorrectly. In order to fix this you need to rename the SCRIPT_NAME parameter to PATH_INFO.

    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    
    Send feedback   このエントリーを含むはてなブックマーク はてなブックマーク - Django and nginx settings