Metin Devekaya
Metin Devekaya

Reputation: 61

Django on lighttpd: redirecting to .fcgi (404)

I'm in the process of deploying my django project to a lighty server. When I'm trying to access the website root, everything is fine, but if I add /admin/ or /blog/ I get:

Page not found (404)
Request Method:     GET
Request URL:    http://x.x.x.x/mysite.fcgi/mysite.fcgi/admin/

and,

Page not found (404)
Request Method:     GET
Request URL:    http://x.x.x.x/mysite.fcgi/mysite.fcgi/blog/

I've read a few posts about this and it seems to be solved by adding: FORCE_SCRIPT_NAME = "" to settings.py. However, that has not worked for me.

urls.py:

urlpatterns = patterns('',
(r'^$', index),
(r'^blog/$', blog_view),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)

lighttpd.conf:

$HTTP["host"] == "x.x.x.x" {
server.document-root = "/home/lighttpd/sedin/web"
fastcgi.server = (
    "/mysite.fcgi" => (
        "main" => (
            # Use host / port instead of socket for TCP fastcgi
            #"host" => "127.0.0.1",
            #"port" => 3033,            
            "socket" => "/home/lighttpd/sedin/sedin.sock",
            "check-local" => "disable",
            #"fix-root-scriptname" => "enable", #also tried this, but didn't work
        )
    ),
)
alias.url = (
    "/static/admin/" => "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/",
    "/media/" => "/home/lighttpd/sedin/media/",
    "/static/" => "/home/lighttpd/sedin/web/static/",
)

url.rewrite-once = (
    "^(/static.*)$" => "$1",
    "^(/media.*)$" => "$1",
    "^/favicon\.ico$" => "/media/favicon.ico",
    "^(/.*)$" => "/mysite.fcgi$1",
)
}

Upvotes: 2

Views: 1617

Answers (3)

gen1us
gen1us

Reputation: 51

Add to your settings.py:

FORCE_SCRIPT_NAME = ''

https://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#forcing-the-url-prefix-to-a-particular-value

fix-root-scriptname fixes lighttpd bug when you use fastcgi.server = ( "/" instead of fastcgi.server = ( "/mysite.fcgi"

Upvotes: 5

jedie
jedie

Reputation: 1853

There exist a ticket for this: https://code.djangoproject.com/ticket/11694

Upvotes: 0

Metin Devekaya
Metin Devekaya

Reputation: 61

I solved this problem by killing all running fastcgi processes and starting a new one. I wasnt aware that fcgi had to be restarted everytime I made a change to the projects .py-files.

Upvotes: 1

Related Questions