Home>

If i call the following cgi (60a11.cgi) from index.html on CentOS7,

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root @ localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

is displayed and the target cgi is not displayed.
60a11.cgi is the following code.

#!/usr/bin/perl
use strict;
use utf8;
print "Content-type: text/html \ n \ n";
print<<"HTML";
<! DOCTYPE html PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN">
<html>
<head>
<title>User Account Registration</title>
</head>
<body bgcolor = "# 000066" text = "# 000000" link = "# 0000ee" alink = "# 0000ee" vlink = "# 551a8b">
<form method = "post" form action = "67b32.cgi" ENCTYPE = "multipart/form-data">
<table border = "0"&​​gt;
<tr>
<td><font color = "# ff0000"><label for = "ID">desired user ID</label></font></td>
<td><input type = "text" name = "ID" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "pass">preferred password</label></font></td>
<td><input type = "password" name = "pass" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "pass2">password verification</label></font></td>
<td><input type = "password" name = "pass2" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "shimei">Name</label></font></td>
<td><input type = "text" name = "shimei" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "kaisyamei">Company Name</label></font></td>
<td><input type = "text" name = "kaisyamei" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "mail">email address</label></font></td>
<td><input type = "text" name = "mail" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "syouhinmei">product name</label></font></td>
<td><input type = "text" name = "syouhinmei" size = "40" maxlength = "30"><br></td>
</tr><tr>
<td><font color = "# ff0000"><label for = "nedan">Product Price</label></font></td>
<td><input type = "text" name = "nedan" size = "40" maxlength = "30"><br></td>
</tr><tr><td><font color = "# ff0000"><label for = "q1">Product Category</label></font></td>
<td><input type = "radio" name = "q1" value = "[book (actual product)]"><font color = "# ff0000">book</font>
<input type = "radio" name = "q1" value = "[CD (actual product)]"><font color = "# ff0000">CD</font>
<input type = "radio" name = "q1" value = "[DVD (actual product)]"><font color = "# ff0000">DVD</font>
<input type = "radio" name = "q1" value = "[Software (actual product)]"><font color = "# ff0000">
Software (actual)</font>
<input type = "radio" name = "q1" value = "[video game (actual product)]"><font color = "# ff0000">video game (actual)</font>
<input type = "radio" name = "q1" value = "[electronic book (electronic file)]"><font color = "# ff0000">electronic book</font>
<input type = "radio" name = "q1" value = "[software (electronic file)]"><font color = "# ff0000">software (electronic file)</font>
<input type = "radio" name = "q1" value = "[music (electronic file)]"><font color = "# ff0000">music (electronic file)</font>
<input type = "radio" name = "q1" value = "[video game (electronic file)]"><font color = "# ff0000">video game (electronic file)</font>
<input type = "radio" name = "q1" value = "[video (electronic file)]"><font color = "# ff0000">video (electronic file)</font><br&gt ;</td>
</tr><tr>
<td><font color = "# ff0000">File 1: Image file (jpg/gif/png/bmp file)<br>File 2: Reading file (pdf file) No need)<br>File 3: Upload the content I want to sell (you don't need to upload it if you ’re dealing with real products)</font><br></td>
</tr><tr>
<td><font color = "# ff0000">Select file 1:</font></td>
<td><font color = "# ff0000"><input type = "file" name = "file1"></font><br></td>
</tr><tr>
<td><font color = "# ff0000">Select file 2:</font></td>
<td><font color = "# ff0000"><input type = "file" name = "file2"></font><br></td>
</tr><tr>
<td><font color = "# ff0000">Select file 3:</font></td>
<td><font color = "# ff0000"><input type = "file" name = "file3"></font><br></td>
</tr><tr>
<td><textarea name = "mojijouhou" rows = "4" cols = "40">Please enter product information.</textarea><br></td>
</tr><tr>
<td><input type = "submit" onclick = "location.href'67b32.cgi '" value = "submit">
<input type = "reset" value = "reset"></td>
</tr>
</table>
</form>
</body>
</html>
HTML
exit;


Perl made with WINDOWS was ported to CentOS7.
error_log is as follows.

[Tue Aug 14 16: 30: 29.805758 2018] [core: error] [pid 2530] (13) Permission denied: [client 127.0.0.1:35185] AH00132: file permissions deny server access:/var /www/html/buhin/btn056_09_4.gif, referer: http://127.0.0.1/
[Tue Aug 14 16: 30: 29.805935 2018] [core: error] [pid 2531] (13) Permission denied: [client 127.0.0.1:35186] AH00132: file permissions deny server access:/var/www/html/buhin /btn056_09_5.gif, referer: http://127.0.0.1/
[Tue Aug 14 16: 30: 29.808047 2018] [core: error] [pid 2528] (13) Permission denied: [client 127.0.0.1:35188] AH00132: file permissions deny server access:/var/www/html/buhin /btn056_09_7.gif, referer: http://127.0.0.1/
[Tue Aug 14 16: 30: 35.294682 2018] [cgi: error] [pid 3667] [client 127.0.0.1:35189] AH01215: (8) Exec format error: exec of '/ var/www/cgi-bin/60a11 .cgi 'failed, referer: http://127.0.0.1/
[Tue Aug 14 16: 30: 35.297373 2018] [cgi: error] [pid 3667] [client 127.0.0.1:35189] End of script output before headers: 60a11.cgi, referer: http://127.0.0.1/


This is the third time in this theme. Thank you.

  • Answer # 1

    Run the script on the command line and you should get the following output:

    Content-type: text/html
    Wide character in print at /home/kdoi2/work/test3.pl line 6.
    <! DOCTYPE html PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN">
    <html>
    <head>
    <title>User Account Registration</title>
    Abbreviated

    This third line wide ... is the direct cause. Because of this, cgi is regarded as an "invalid header" and results in a notation error.

    The reason why this happens is that I haven't done any Japanese encoding.

    And that has been pointed out in past questions. Since the questioner doesn't listen to the advice, there is no progress and the third question is forced.

  • Answer # 2

    Cause of internal server error

    Perhaps because cgi script file does not have execute permission.
    Give appropriate execution authority.
    This is the cause of both the bottom two lines of error_log.
    (An error saying that the program ended before the http response header, ieContent-type, etc.) was output!

    About wide character messages

    The direct cause is that you areuse utf-8but not handling theutf-8 flagproperly.
    Maybe I don't know so, addbinmode (STDOUT,": utf8");underuse utf-8;oruse utf- 8;should be deleted. This will stop the warning message.

    If you continue with perl, I'd like you to understand the meaning of theuse utf-8and utf-8 flags. I think that it is enough to be "not magical". It will be a problem if you start processing strings.

  • Answer # 3

    Permission denied
    → The web server program tried to read the file, but was denied because of insufficient access rights.
    →→ Review the owner and group of the file, or review the access rights. If troublesome, give r to owner, group, and others.

    Exec format error
    → Is there something wrong with the cgi file startup, or is Perl not in the/usr/bin/perl location?
    →→ Check server specifications again.

    In addition,
    The encoding when saving the file may be wrong.
    Check if it is UTF-8 or BOM.


    If you let ActivePerl process at the command prompt,
    At first glance the standard output seems to be okay, but
    As error output

      

    C: \ Users \ m6u \ Documents>perl StackOverflow.pl | more
      Wide character in print at StackOverflow.pl line 6.
      Content-type: text/html

      

    <! DOCTYPE html PUBLIC"-// W3C // DTD HTML 4.01 Transitional // EN">
      <html>
      <head>
      <title>Corporate Crawling</title>

    Because it looks like this, it would be better to take measures against this as well.
    When I print a character string, I was in trouble because "Wide character in print at" was output-English and programming whimsical diary

  • Answer # 4

    For now, there is information like that in the error log, so search it First narrow down the information.

      

    Exec format error: exec of'/var/www/cgi-bin/60a11.cgi'failed

    Because it is

    , it may not be considered a valid executable. It is likely that extra\ r(CR) is inserted due to the line feed code.

    Appendix--

    If the original script is derived from Windows environment, it may be UTF-8 with BOM. The first 2 bytes of the file need to be exactly "#!", So if there is a BOM that occupies the first 3 bytes of the file, it will not be considered as an executable program, so this is also the cause Get.

    Although it is not related to cgi itself,

      

    Permission denied: (omitted) file permissions deny server access: /var/www/html/buhin/btn056_09_4.gif

    Is this an image file also considered an executable program? (And it is permission denied because there is no execution right)
    If you useScriptAlias ​​in Apache settings, all the files in the specified directory are regarded as cgi programs. In such cases, non-program files such as images should not be placed in the same location.

    If you are using

    ScriptAlias ​​, move files such as images to another directory (adjust the file/directory information in the program accordingly) orScriptAlias Instead of, it is better to think about setting cgi execution separately forAlias ​​andSetHandler.