简体   繁体   中英

How to configure lighttpd to serve django static files?

I have a web application made with Django 2.0.5, installed in a virtual environment on Debian 9, on which I installed Gunicorn and lighttpd. I installed my web app in /opt/djangoproject/mywebapp. I configured lighttpd adding these lines to my lighttpd.conf

$HTTP["url"] !~ "/static" {
proxy.server = ( "" => ( (
"host" => "192.168.1.15", 
"port" => 8001
) ) )
}

alias.url = ( "/static/" => "/opt/djangoproject/mywebapp/mystaticfiles" )

The problem is that the alias only work on port 80 instead of to work on 8001.

Update: I forgot to specify that:

  • Gunicorn run only on 192.168.1.15:8001 (with this static ip)
  • Lighttpd run on port 80 (default port)
  • Debian is installed on a server I have to reach from every device connected on the same network

Based on the description, it sounds like lighttpd is running on port 80 and gunicorn on port 8001. If gunicorn is creating content that refers to port 8001, then the client will connect directly to gunicorn (if gunicorn is listening on *:8001 instead of 127.0.0.1:8001) and will bypass lighttpd, so lighttpd never sees it. You should prefer to use root-relative links (starting with / in the url-path).

I understood where the problem was. The configuration was right, but I forgot to include "mod_proxy" in server.modules. After adding the module (and restart lighttpd) everything worked. I hope it will be useful to someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM