Project

General

Profile

[Solved] CGI does not work. lighttpd returns "500 - Internal Server Error"

Added by miminashi about 6 years ago

  • OS: macOS Sierra 10.12.6
  • lighttpd: 1.4.48

directory structure

$ ls -R
lighttpd.conf www

./www:
cgi-bin    index.html

./www/cgi-bin:
hello.cgi

lighttpd.conf

server.document-root = "www" 

server.port = 3000

server.modules += ( "mod_accesslog", "mod_alias", "mod_cgi" )
cgi.assign = ( ".cgi" => "" )

index-file.names = ( "index.html" )

hello.cgi

#!/bin/sh

printf 'Content-Type: text/html; charset=UTF-8\r\n\r\n'
printf 'Hello, World\r\n'

and this script itself works well...

$ ./www/cgi-bin/hello.cgi 
Content-Type: text/html; charset=UTF-8

Hello, World

starts lighttpd

$ lighttpd -D -f lighttpd.conf
2018-02-06 22:35:02: (server.c.1412) server started (lighttpd/1.4.48) 

access to /cgi-bin/hello.cgi

$ curl http://localhost:3000/cgi-bin/hello.cgi
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>500 - Internal Server Error</title>
 </head>
 <body>
  <h1>500 - Internal Server Error</h1>
 </body>
</html>

message from lighttpd in the console

www/cgi-bin/hello.cgi: No such file or directory

What's wrong?
Please help me, thanks.


Replies (2)

RE: CGI does not work. lighttpd returns "500 - Internal Server Error" - Added by stbuehler about 6 years ago

Use an absolute path for server.document-root (maybe server.document-root = env.PWD + "/www").

RE: CGI does not work. lighttpd returns "500 - Internal Server Error" - Added by miminashi about 6 years ago

great! It works!
Thank you!

Currently, the contents of lighttpd.conf is:

server.document-root = env.PWD + "/www" 

server.port = 3000

server.modules += ( "mod_accesslog", "mod_alias", "mod_cgi" )
cgi.assign = ( ".cgi" => "" )

index-file.names = ( "index.html" )

    (1-2/2)