Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The server is Linux and running lighttpd The test code in "C" is like below (test.c)

#include <stdio.h>
int main ()
{
 printf ("Welcome to CGI");
return 0;
}

I compiled the code to generate CGI like below

gcc test.c -o test.cgi

I put the generate test.cgi file in web/cgi-bin/ folder and it showing following error while accessing it fron browser /cgi-bin/test.cgi

500 Internal Server Error

The log file consists of

2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.628) Path         : /filesys/web/cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.652) -- logical -> physical
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.653) Doc-Root     : /filesys/web/
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.654) Basedir      : /filesys/web/
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.655) Rel-Path     : /cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.656) Path         : /filesys/web/cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.668) -- handling physical path
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.669) Path         : /filesys/web/cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.676) -- handling subrequest
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.677) Path         : /filesys/web/cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.678) URI          : /cgi-bin/test.cgi
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/response.c.679) Pathinfo     :
2021-01-04 04:56:32: (../../lighttpd-1.4.53/src/mod_access.c.177) -- mod_access_uri_handler called
question from:https://stackoverflow.com/questions/65559768/500-internal-server-in-lighttpd-while-calling-cgi-written-in-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
832 views
Welcome To Ask or Share your Answers For Others

1 Answer

As noted by @basile-starynkevitch, your program output is not compliant with the (very simple) CGI protocol. However, lighttpd will still handle that.

You did not share your lighttpd.conf (lighttpd -f /etc/lighttpd/lighttpd.conf -p), so I am guessing that you did not properly configure lighttpd mod_cgi to handle the request.

The user account under which the web server is running should have filesystem access to the path and files wherever your web/cgi-bin/ is located.

If this has never worked for you, then also check to see if SELinux is blocking the CGI execution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...