TransWikia.com

"404 not found" error when requesting Python with Lighttpd through CGI

Raspberry Pi Asked by Seph Reed on January 4, 2021

I’ve installed lighttpd and gotten it to serve /var/www/index.html just fine, but I haven’t gotten it to run a Python script yet.

I enabled CGI and set it’s match case and directory as instructed in this SO answer. In short, I added mod_cgi to server.modules() and gave it a regex rule

$HTTP["url"] =~ "^/cgi-bin/" {
    cgi.assign = ( ".py" => "/usr/bin/python" )
}

For my test file /var/www/cgi-bin/test.py:

print "Content-Type: text/html"     
print ""                              
print "<body>"
print "TEST"
print "</body>"
print "</html>"

When I enter the url raspberrypi.local or my IP, I get the file /var/www/index.html as expected. When I request the url raspberrypi.local/cgi-bin/test.py or raspberrypi.local/test.py I get a 404 error.

How can I solve this problem?

EDIT: I’ve also found this tutorial which is very good, and says pretty much the same thing. I’m still getting the 404 error.

One Answer

Please follow this steps:

First enable cgi by

sudo lighttpd-enable-mod cgi

This creates a new configuration file for Lighttpd:

/etc/lighttpd/conf-enabled/10-cgi.conf

Edit the configuration file nano /etc/lighttpd/conf-enabled/10-cgi.conf, to look similar to this

server.modules += ( "mod_cgi" )

$HTTP["url"] =~ "^/cgi-bin/" {
        alias.url += ( "/cgi-bin/" => "/var/www/cgi-bin" )
        cgi.assign = (
                ".py"  => "/usr/bin/python",
        )
}

Make sure python 2 is installed by executing:

/usr/bin/python --version

Now, restart

sudo /etc/init.d/lighttpd force-reload

Good luck!

Answered by NDB on January 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP