Have Apache support the configuration methods of cgi SSI shtml

  • 2020-05-06 12:09:37
  • OfStack

1. First, make it clear that only a certain directory can be specified to support cgi, that is, run the directory to execute cgi program; It's not safe.
Looking for:


    #
    # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "E:/Website_Field/cgi">
        AllowOverride all
        Options all
        Order allow,deny
        Allow from all
    </Directory>

Set Directory to

, where cgi can be executed

2.
Looking for:


    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    ScriptAlias /cgi-bin/ "E:/Website_Field/cgi"

Change the following directory to be the same as above.

3.
Set the cgi script suffix, looking for:


   #
    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    #
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #
    AddHandler cgi-script .cgi .pl

Set suffixes like.cgi,.pl, etc., anything you can think of, but avoid using existing ones like.html,.asp,.php,

, etc

Note: after setting up a directory that supports cgi, the contents of that directory and the contents of the subdirectories can be executed.

Configure Apache to support SSI, server-parsed html (shtml)
as resolved on the server side For more on what SSI is and what shtml is, see the other two articles on this site.
SSI can be used to dynamically embed html content, can return results for the following SSI commands, or even the system, as well as the more common call Perl program (perl cgi returns results)

1. Configure Apache:
1) first find:


   #
    # To use server-parsed HTML files
    #
    AddType text/html .shtml
    AddHandler server-parsed .shtml

Get rid of the # before the last two lines;
2) you also need to specify which directory supports this resolution, look for:


  #
    # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "E:/Website_Field/shtml">
        AllowOverride all
        Options all
        Order allow,deny
        Allow from all
    </Directory>

Change from Directory:
First specify to their own directory, here is "E:/Website_Field/shtml";
Then set the options as shown:


AllowOverride all
Options all
Order allow,deny
Allow from all
 

Restart Apache after that.

2. For the SSI directive supported by Apache, please refer to the following introduction:
//www.jb51.net/tools/onlinetools/apache-chs/howto/ssi.html

3. An shtml page instance using SSI:
1), index shtml


<html>
<head>
   <title>shtml</title>
</head>
<body>
<!--#config timefmt="%D" -->
  This file last modified <!--#echo var="LAST_MODIFIED" --><br />
  <!--#config timefmt="%A %B %d, %Y" -->
  Today is <!--#echo var="DATE_LOCAL" --><br />
 <!--#include virtual="embed.html" --><br />
 <!--#exec cmd="test.pl" --><br />
 <!--#exec cmd="dir" --><br />
</body>
</html>

2), embed html


<html>
<head>
    <title>embed html</title>
</head>
<body>
This is the content from embed.html
</body>
</html>

3), test pl


#!C:\perl\bin\perl -w
use strict;
sub print_header()
{
    print "This is Header function! ";   
}
sub print_footer()
{
    print "This is Footer function! ";   
}
print_header();
print_footer();

Conclusion:
Setting Apache to support cgi has the same section as SSI, setting Directory to the same directory.
Therefore, if ssi is used alone, it can be configured according to the Settings of ssi, and shtml etc. can be placed in the directory set.
If Apache is set to support cgi, simply open ssi and place shtml and other files in the cgi directory.


Related articles: