lighttpd and scgi

2 views
Skip to first unread message

Anil

unread,
Jun 29, 2009, 2:52:17 PM6/29/09
to pylons-...@googlegroups.com
Couple of you helped me out on IRC regarding this (actually pointed to better solutions... thanks) but I am curious why my deployment using lighttpd and scgi doesnt work.

I have a dev environment where I do not have a web server, just using paster. The same code breaks when I use lighttpd and scgi. The CSS/images fail to load.

In dev, I have URLs like http://url/css/base.css. In production, the same url is returning a 404. Instead, they are become http://url/css/css/base.css. I am simply doing:
${h.stylesheet_link('/css/base.css')}



My lighttpd configuration:

$HTTP["host"] =~ "^(www\.)?domain\.net$" {
  server.name = "domain.net"
  server.document-root = "/home/admin/Pages/Domain"
  $HTTP["scheme"] == "http" {
    url.redirect = ("^/(login)" => "https://domain.net/$1",
                    "^/(register)" => "https://domain.net/$1")
  }
  scgi.server = ("/" =>
    ((
      "host" => "127.0.0.1",
      "port" => 6500,
      "min-procs" => 1,
      "max-procs" => 2,
      "check-local" => "disable"
    ))
  )
}

What is causing the /public directory to not work?

Thanks


Didip Kerabat

unread,
Jun 29, 2009, 8:40:50 PM6/29/09
to pylons-...@googlegroups.com
Is /home/admin/Pages/Domain your project root path?

As simple example, here's my lighttpd setup:

server.document-root = "/my/project/root/"

## SCGI Settings
$HTTP["url"] !~ "^/public/" { # If URL is NOT /public/
  # Root config

  scgi.server = ("/" =>
    ( "ServerIPAddress" => (

      "host" => "127.0.0.1",
      "port" => 6500,
      "min-procs" => 5,
      "max-procs" => 10,
      "check-local" => "disable")
    )
  )
}

- Didip -

pepijn

unread,
Jul 4, 2009, 5:13:04 AM7/4/09
to pylons-discuss
"actually pointed to better solutions... thanks"
Can you share your solution please?
I am also trying to run Pylons with Lighttpd...

Thanks!

Pepijn

On Jun 29, 8:52 pm, Anil <replic...@gmail.com> wrote:
> Couple of you helped me out on IRC regarding this (actually pointed to
> better solutions... thanks) but I am curious why my deployment using
> lighttpd and scgi doesnt work.
>
> I have a dev environment where I do not have a web server, just using
> paster. The same code breaks when I use lighttpd and scgi. The CSS/images
> fail to load.
>
> In dev, I have URLs likehttp://url/css/base.css. In production, the same
> url is returning a 404. Instead, they are becomehttp://url/css/css/base.css.

Audrius Kažukauskas

unread,
Jul 5, 2009, 5:22:11 AM7/5/09
to pylons-...@googlegroups.com
On Sat, 2009-07-04 at 02:13:04 -0700, pepijn wrote:
> "actually pointed to better solutions... thanks"
> Can you share your solution please?
> I am also trying to run Pylons with Lighttpd...

Maybe he means mod_proxy? At least for me it was a simpler solution.
Mainly because it worked right from the beginning.

To use lighttpd as a reverse proxy you need to uncomment/add mod_proxy
in server.modules. Then somewhere in your config file below put
something like this:

$HTTP["host"] =~ "^foobar\.example\.org$" {
$HTTP["url"] =~ "^/(script|style)/" {
server.document-root = "/path/to/static/docs"
}
$HTTP["url"] !~ "^/(script|style)/" {
proxy.server = ("" => ( ("host" => "127.0.0.1", "port" => 5000) ) )
}
}

This is the rule for single domain (but you can use it any way you like by
changing regexp), which contains two URL rules. The first one is for static
files, the second one is for everything *except* static files and points to
your WSGI server (or servers; there can be more than one for load balancing; if
you're interested, read the docs), which can be paste.httpserver or whatever
you prefer (CherryPy's WSGI server, Spawning, etc).

There are various ways how to start and manage your WSGI server. I've
written simple init scripts, since I don't have any special requirements
for my personal stuff, but people here several times were discussing
about supervisor, monit and some other names I don't recall at the
moment. You can look into the mailing list archives for deployment
discussions.

Also to avoid serving static files via Pylons while in production mode,
modify the last two lines before return in config/middleware.py:

if config['debug']:
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, app])

Oh, and if you need an IP of the client connecting to your server, you
can get it from environ['HTTP_X_FORWARDED_FOR']. REMOTE_ADDR will
always contain an IP of computer lighttpd is running on (if it's the
same for WSGI server, it'll be 127.0.0.1).

HTH,
--
Audrius Kažukauskas

Reply all
Reply to author
Forward
0 new messages