Project

General

Profile

[Solved] lighttpd reverse proxy always get http error 500

Added by xiaoxiyin about 5 years ago

hi all experts,
this question confused me lots of days. i really need your help and great thanks in advance.
Server A: lighttpd 1.4.42 + mod_proxy, ip 135.251.124.94
Server B: another web server, an easy web to invoke a shell cgi script to write file, ip 10.9.131.90

as client, if i access Server B directly, everything works fine.
but if i want to access Server B from Server A(Server A set as reverse proxy), i always get "HTTP 500 Internal Server Error".

from error.log,
2016-11-04 10:58:29: (log.c.217) server started
2016-11-04 10:58:35: (request.c.436) fd: 8 request-len: 438 \nPOST /cgi-bin/mailer HTTP/1.1\r\nAccept: text/html, application/xhtml+xml, /*\r\nReferer: http://135.251.124.94:8321/test2.html\r\nAccept-Language: zh-CN\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip, deflate\r\nHost: 135.251.124.94:8321\r\nContent-Length: 26\r\nPragma: no-cache\r\nConnection: Keep-Alive\r\nX-BlueCoat-Via: 951d499292535715\r\n\r\n
2016-11-04 10:58:35: (mod_proxy.c.1157) proxy - start
2016-11-04 10:58:35: (mod_proxy.c.1198) proxy - ext found
2016-11-04 10:58:35: (mod_proxy.c.1334) proxy - found a host 10.9.131.90 80
2016-11-04 10:58:35: (mod_proxy.c.416) connect delayed: 9
2016-11-04 10:58:35: (mod_proxy.c.1041) proxy: fdevent-out 1
2016-11-04 10:58:35: (mod_proxy.c.1064) proxy - connect - delayed success
2016-11-04 10:58:35: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:35: (mod_proxy.c.651) proxy - have to read: 9
2016-11-04 10:58:35: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:35: (mod_proxy.c.651) proxy - have to read: 12
2016-11-04 10:58:36: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:36: (mod_proxy.c.651) proxy - have to read: 25
2016-11-04 10:58:37: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:37: (mod_proxy.c.651) proxy - have to read: 1
2016-11-04 10:58:37: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:37: (mod_proxy.c.651) proxy - have to read: 16
2016-11-04 10:58:37: (mod_proxy.c.1029) proxy: fdevent-in 4
2016-11-04 10:58:37: (mod_proxy.c.651) proxy - have to read: 0
*2016-11-04 10:58:37: (response.c.122) Response-Header: \nHTTP/1.1 500 Internal Server Error\r\nContent-Type: text/html\r\nContent-Length: 369\r\nDate: Fri, 04 Nov 2016 02:58:37 GMT\r\nServer: lighttpd/1.4.42\r\n\r\n

my mod_proxy config as below:
$HTTP["url"]=~"(cgi-bin|html)"{
proxy.server = ( "" =>
( "" =>
(
"host" => "10.9.131.90",
"port" => 80
)
)
)
}

test.zip (2.86 KB) test.zip test zip on server B

Replies (2)

RE: lighttpd reverse proxy always get http error 500 - Added by gstrauss about 5 years ago

I suggest adding some logging to your server B to find out what it is sending back to lighttpd. Also, please test using lighttpd 1.4.43, which was recently released.

RE: [Solved] lighttpd reverse proxy always get http error 500 - Added by gstrauss almost 5 years ago

Sorry, I hadn't noticed that you included test.zip with files demonstrating what you were doing.

The answer is still to look at what Server B is sending back to lighttpd. Alternatively, use mod_cgi Docs_ModCGI to execute the CGI.

For your own script debugging, you probably want to change your mailer script to reorder some lines from

echo "Status: 200\r\n\r\n" 
eval `./proccgi.sh $*`
echo Content-type: text/plain

to instead be:
echo "Status: 200" 
echo Content-type: text/plain
echo
eval `./proccgi.sh $*`

Depending on the server, CGI scripts need only end lines with newline (LF) instead of carriage-return, line feed (CRLF).
Proxies should return HTTP response headers ending CRLF.
If using shell syntax, you might want to use echo -en "something\r\n"
The -e interprets some backslash-escapes such as \r\n, and the -n suppresses 'echo' adding an additional newline at the end of the expression.

    (1-2/2)