Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
830 views
in Technique[技术] by (71.8m points)

webserver - 500 Internal server in lighttpd while calling CGI written in "C"

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...