Lighttpd and cgi python
Asked Answered
D

3

5

I'm trying to execute some python scripts through lighttpd but when I try to run it, I only get a blank file which I'm asked to download.

lighttpd.conf

server.modules  = (
            "mod_access",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
            "mod_rewrite"
)

server.port                 = 8080
server.bind                 = "127.0.0.1"
server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"



index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                               " index.lighttpd.html" )


url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

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

server.modules += ( "mod_cgi" )

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

## Warning this represents a security risk, as it allow to execute any file
## with a .pl/.py even outside of /usr/lib/cgi-bin.
#
cgi.assign      = (
#   ".pl"  => "/usr/bin/perl",
    ".py"  => "/usr/bin/python"
)

/var/www/cgi-bin/hellopy.py

print "Content-Type: text/html"
print
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"

I really don't understand what's happening.

Dint answered 31/7, 2012 at 9:36 Comment(3)
The complete lighttpd.conf is not necessary.Worlock
Sorry, but it was in prevention of any helper to ask me to post it :DDint
Have you tried setting the execute bit on the file?Chemo
W
3

Remove the 'default' assign

cgi.assign = ( "" => "" )

and use only the second one, perhaps inside the match.

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

Edit

And make sure that /usr/bin/python exists.

Worlock answered 31/7, 2012 at 9:40 Comment(1)
Nope, already tried, (and tried again) =/, /usr/bin/python exists. But Thanks :)Dint
I
0

Make sure you have the following in your Lighttpd's mimetypes configuration file:

".py" => "text/x-python",
".pyc" => "application/x-python-code",
".pyo" => "application/x-python-code",
Incompetence answered 23/11, 2013 at 22:19 Comment(0)
P
0

I was running into this issue too. By default, the cgi module is disabled. To enable, try running sudo lighttpd-enable-mod cgi and then /etc/init.d/lighttpd force-reload and try again. Also keep in mind that if you have set cgi.execute-x-only = enable that you need to make your cgi scripts executable e.g. chmod a+x index.py.

If that still doesn't work, you can try adding "mod_cgi" to your server.modules array.

Peterus answered 2/4, 2018 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.