I have a simple Django application that I am using to test out a new deployment strategy using Nginx, FastCGI (using the latest version of flup at the time of writing) and daemontools.

Basically the problem is if I visit domain.com the main page displays correctly but if I visit domain.com/example/ it still displays the main page. This seems like a problem with FastCGI to me but I'm completely stumped. No matter what page I visit it always displays the main page. No errors, nothing. Its like it always just silently returns the same page no matter what the url.

The nginx error log has absolutely nothing displayed in it at all so that is no help. The project works 100% perfectly using the development server but just fails on the server.

My daemontools run file is as follows:

#!/usr/bin/env bash

source /envs/domain.com/bin/activate

exec envuidgid simon python $PROJ_DIR/manage.py \
        runfcgi method=threaded minspare=1 maxspare=2 host= \
        port=9001 pidfile=$PROJ_DIR/proj.pid daemonize=false

My nginx config:

server {
    listen 80;
    server_name domain.com;
    rewrite ^/(.*) http://www.domain.com/$1 permanent;

server {
    listen 80;
    server_name www.domain.com;

    access_log /domain.com/logs/access.log;
    error_log /domain.com/logs/error.log;

    root /domain.com/public_html;
    index index.html;

    location / {
        try_files $uri @django;

    location /static {
        alias /project/static;

    location /media {
        alias /project/media;

    location @django {
        include /opt/nginx/conf/fastcgi_params;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;

Any help would be very much appreciated :).


What do you have in fastcgi_params? You should have something like:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  PATH_INFO          $fastcgi_script_name;

Also set in settings.py:


This is one way to do it. You can also leave FORCE_SCRIPT_NAME on the default and configure everything through nginx.

  • Thank you! If anyone else is having these issues the magic was in setting FORCE_SCRIPT_NAME = '' in settings.py and adding fastcgi_param PATH_INFO $fastcgi_script_name; to fastcgi_params. – Cromulent Mar 12 '11 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.