Project

General

Profile

fcgi, ssl and django, redirect HTTP to HTTPS

Added by jmat over 13 years ago

I have a django site setup with lighttpd and ssl working but I can not seem to get a redirect to work from http to https. My setup is very similar to: https://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#lighttpd-setup and I'm using lighttpd/1.4.26 on ubuntu

Basically my setup looks something like this:

$HTTP["host"] =~ "myhost.com" {
server.document-root = "/home/myvenv/blah" 
fastcgi.server = ( 
    "/blah.fcgi" => (
        (   
            "host" => "127.0.0.1",
            "port" => 16666,
            "check-local" => "disable",
            "max-procs" => 4,
            "min-procs" => 4,
        )   
    )   
)
url.rewrite-once = ( 
    "^(/favicon.ico.*)$" => "/$1",
    "^(/admin_media.*)$" => "/$1",
    "^(/media.*)$" => "/$1",
    "^(/.*)$" => "/blah.fcgi$1",
)

expire.url = ( 
    "/favicon.ico" => "access 1 seconds",
    "/admin_media" => "access 1 seconds",
    "/media" => "access 1 seconds",
)

}

I want to add this to do my http to https redirect:

$SERVER["socket"] == ":80" {
  $HTTP["host"] =~ "(.*)" {
    url.redirect = ( "^/(.*)" => "https://%1/$1" )
  }
}

The problem is when I enable the redirect, my url gets rewritten like:

https://myhost.com/blah.fcgi/my/path/to/blah

putting in the blah.fcgi part when I really just want:

https://myhost.com/my/path/to/blah

Much thanks in adavance.


Replies (1)

RE: fcgi, ssl and django, redirect HTTP to HTTPS - Added by jmat over 13 years ago

I got an answer for this on stackoverlow:

http://stackoverflow.com/questions/8331567/fcgi-ssl-and-django-redirect-http-to-https

It really was me just not thinking about regexing the rewrite part.

I'm wondering though, why does the rewrite happen before the redirect?

    (1-1/1)