Running Django admin site using Lighttpd

10 views
Skip to first unread message

Karim Hamdan

unread,
Apr 8, 2009, 8:30:25 PM4/8/09
to Django users
Hi all,

I have been trying to run my django site using lighttpd rather than
using the development server that is shipped with django and I managed
to run the site of the project but I failed to run the admin site. Any
ideas how I can approach this problem?

Thanks.

--
Karim Hamdan

Karen Tracey

unread,
Apr 8, 2009, 9:06:42 PM4/8/09
to django...@googlegroups.com

Give some details on "failed to run the admin site"?  "It doesn't work" doesn't give anyone much to go on in terms of helping you.

Karen


 

Karim Hamdan

unread,
Apr 8, 2009, 9:59:23 PM4/8/09
to django...@googlegroups.com
When I try to access the admin site using "http://localhost/admin" I get a 404 not found error instead of getting the login page to enter my admin credentials to log in the admin site.

--
Karim Hamdan

Karim Hamdan

unread,
Apr 9, 2009, 10:35:11 AM4/9/09
to django...@googlegroups.com
Let me rephrase my question. I followed this HowTo on this group that describes how to run Django using lighty with fcgi, I can access my project website successfully but I fail to access Django's admin site and get a 404 Not Found error instead. I am running lighttpd-1.4.19 and python-django 1.0-1ubuntu1 on my Ubuntu Intrepid machine.

--
Karim Hamdan

Karen Tracey

unread,
Apr 9, 2009, 10:48:02 AM4/9/09
to django...@googlegroups.com
On Thu, Apr 9, 2009 at 10:35 AM, Karim Hamdan <karim...@gmail.com> wrote:
Let me rephrase my question. I followed this HowTo on this group that describes how to run Django using lighty with fcgi, I can access my project website successfully but I fail to access Django's admin site and get a 404 Not Found error instead. I am running lighttpd-1.4.19 and python-django 1.0-1ubuntu1 on my Ubuntu Intrepid machine.

I'm not familiar with kind of setup at all, but those instructions appear to involve configuring things so that admin urls are served by a server running on a different port than your main Django server.  I don't know why that would be necessary, but if you have followed those instructions and you are not actually running a 2nd server on the 2nd port to serve admin, that could be a problem.  If there is no reason you have for wanting to serve admin from an entirely different Django server instance, then I'd get rid of the admin.fcgi rewrites and server config information, and just send all urls to your main Django server. 

Karen



 

Daniel Roseman

unread,
Apr 9, 2009, 10:51:07 AM4/9/09
to Django users
On Apr 9, 3:35 pm, Karim Hamdan <karimham...@gmail.com> wrote:
> Let me rephrase my question. I followed
> this<http://groups.google.com/group/django-users/browse_thread/thread/8cd8...>HowTo
> on this group that describes how to run Django using lighty with fcgi,
> I can access my project website successfully but I fail to access Django's
> admin site and get a 404 Not Found error instead. I am running
> lighttpd-1.4.19 and python-django 1.0-1ubuntu1 on my Ubuntu Intrepid
> machine.
>
> --
> Karim Hamdan

It would be better if you would 'rephrase' with some examples. What is
your configuration like? What is in your urls.py? Does it work using
the dev server? What's different?
--
DR.

Adam N

unread,
Apr 9, 2009, 1:13:03 PM4/9/09
to Django users
On Apr 9, 10:51 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On Apr 9, 3:35 pm, Karim Hamdan <karimham...@gmail.com> wrote:
>
> > Let me rephrase my question. I followed
> > this<http://groups.google.com/group/django-users/browse_thread/thread/8cd8...>HowTo
> > on this group that describes how to run Django using lighty with fcgi,
> > I can access my project website successfully but I fail to access Django's
> > admin site and get a 404 Not Found error instead. I am running
> > lighttpd-1.4.19 and python-django 1.0-1ubuntu1 on my Ubuntu Intrepid
> > machine.
>

You can also try nginx. The path for nginx seems to be more well trod
by the Django community. Here is my nginx.conf. With that nginx,
Django needs to run under fastcgi:

./manage.py runfcgi host=127.0.0.1 port=8080

-Adam

#######################################################################
#
# This is the main Nginx configuration file.
#
# More information about the configuration options is available on
# * the English wiki - http://wiki.codemongers.com/Main
# * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################

#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
# http://wiki.codemongers.com/NginxMainModule
#
#----------------------------------------------------------------------

user nginx;
worker_processes 2;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;



#----------------------------------------------------------------------
# Events Module
#
# http://wiki.codemongers.com/NginxEventsModule
#
#----------------------------------------------------------------------

events {
worker_connections 1024;
}


#----------------------------------------------------------------------
# HTTP Core Module
#
# http://wiki.codemongers.com/NginxHttpCoreModule
#
#----------------------------------------------------------------------

http {
#auth_basic "Restricted";
#auth_basic_user_file /etc/nginx/.htpasswd;
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local]
$request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

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

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;

#
# The default server
#
server {
listen 80;
server_name _;

#charset koi8-r;

#access_log logs/host.access.log main;
if ($host = 'www.example.com' ) {
rewrite ^/(.*)$ http://example.com/$1 permanent;
}

location ^~ /static/ {
root /var/www/example;
}

location ^~ /media/ {
root /usr/lib/python2.5/site-packages/django/contrib/
admin;
}
location / {
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:8080;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
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;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

}
}

Karim Hamdan

unread,
Apr 9, 2009, 5:13:35 PM4/9/09
to django...@googlegroups.com
Thanks a lot for the replies. It seems that I was following the wrong HowTo. To make things clear, here's what I am trying to do. I am actually new to using Django so I followed the 4 tutorials provided on Django's website, and everything (admin site, polls site) was working fine using the development server. Then, what I am trying to do now is to use lighttpd instead of the dev server so I changed the conf file of lighttpd according to this HowTo that explains how I can use Django with FastCGI (the lighttpd section of the HowTo) so now the polls site is accessible but the admin site gives 404 error. I hope my explanation made things clearer.

Thanks Adam for sharing your conf file but lighttpd is the required server that I should be working with :(

--
Karim Hamdan

stephendwolff

unread,
Apr 10, 2009, 4:06:45 PM4/10/09
to Django users
Here's a lighttpd config (just the part for a single website at
fictional ip '1.2.3.4')

project lives in the 'user' home folder, - _project will be your
django project folder - ie the one with 'manage.py'

look at the lighttpd docs for the specifics of the "main" options.

email me off list if you have any specific examples you want to chat
about...

cheers

Stephen

-----

$SERVER["socket"] == "1.2.3.4" {

server.document-root = "/home/user/_project"
accesslog.filename = "/home/user/_project/log/access.log"

fastcgi.server = (
"/project.fcgi" => (
"main" => (
"bin-path" => "/home/user/_project/www/project.fcgi",
"socket" => "/tmp/projectlivecgi.sock",
"idle-timeout" => 120,
"check-local" => "disable",
"min-procs" => 2,
"max-procs" => 50,
"allow-x-send-file" => "enable",
)
)
)

alias.url = (
"/media/" => "/usr/local/django/trunk/django/contrib/admin/
media/",
"/stats/" => "/home/user/_project/www/stats/",
"/docs/" => "/home/user/_project/docs/",
)

url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/docs.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/stats.*)$" => "/stats/$1",
"^(/.*)$" => "/project.fcgi$1",
)

}
Reply all
Reply to author
Forward
0 new messages