rhl6u083

Lemur zaprasza

Red Hat® Linux 6 Unleashed










Chapter 9: Apache Server





Previous
ChapterNext
Chapter










Sections in this Chapter:








Server
Installation





CGI and SSI






Runtime
Server Configuration Settings





Starting
and Stopping the Server






Virtual
Hosting





Configuration
File Listings

















 

Previous
SectionNext
Section





CGI and SSI
























The
most
common way to provide dynamic content on Web sites is with CGI (Common Gateway
Interface) programs. The CGI is a specification of communication between server
processes (such as programs that generate dynamic documents) and the server
itself. Server Side Includes (SSI) allow output from CGI programs, or other
programs, to be inserted into existing HTML pages.



CGI
By
default,
you may put any CGI program in the ScriptAlias directory on your server. These
programs must be executable by the user as which the server is running. This
usually means that you will need to change the mode of the files to 755 so that
the user nobody can execute them.



chmod 755 program.cgi

In order to execute CGI programs outside of the
ScriptAlias directory, you will need to enable the
ExecCGI option for that directory. This is done
either in your httpd.conf file
(access.conf prior to version 1.3.4) or in an
.htaccess file in the
directory.CGI programs can be written in any
language. The most popular languages for CGI programming are Perl and C. You may
want to pick up a good book on CGI programming, such as CGI Programming With
Perl, Second Edition, since this is not intended to be a CGI
book.To test whether you have CGI configured
correctly, try the following CGI program, written in Perl, which displays the
values of the HTTP environment variables.



#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>Simple CGI program</title></head><body>\n";
for (keys %ENV) {
print "$_ = $ENV{$_}<br>\n";
}
print "</body></html?\n";

If you are going to be writing CGI programs in Perl, you may
want to look at the CGI modules that come bundled with
Perl.



SSI
Server Side Includes (SSI)
are
directives that are written directly into an HTML page, which the server parses
when the page is served to the Web client. They can be used to include other
files, the output from programs, or environment
variables.The most common way to
enable SSI is to indicate that
files with a certain filename extension (typically
.shtml) are to be parsed by the server when they are
served. This is accomplished with the following lines in your
httpd.conf file
(srm.conf prior to version 1.3.4):



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

By uncommenting the AddType and
AddHandler lines, you could tell the server to parse
all .shtml files for SSI
directives.The less commonly used, and in my opinion
much better, way of enabling SSI is with the
XBitHack directive.
XbitHack can be set to a value of on or off, and can
be set in either your configuration file or in
.htaccess files. If the
XBitHack directive is on, it indicates that all
files with the user execute bit set should be parsed for SSI directives. This
has two main advantages. One is that you do not need to rename a file, and
change all links to that file, simply because you want to add a little dynamic
content to it. The other reason is more cosmetic--users looking at your Web
content cannot tell by looking at the filename that you are generating a page
dynamically, and so your wizardry is just that tiny bit more
impressive.In addition to these directives, the
following directive must be specified for directories where you want to permit
SSI:



Options Includes

This may be set in the server configuration file or in an
.htaccess
file.



Basic SSI Directives
SSI directives
look rather like HTML comment tags. The syntax is the following:



<!--#element attribute=value attribute=value ... -->

The element can be one of the
following:






config



 

This
lets you set various configuration options regarding how the document
parsing is handled. Since the page is parsed from top to bottom, config
directives should appear at the top of the HTML document. There
are three configurations that can be set with this command:





 
 

errmsg



 

Sets the error message that is returned to the client
if something goes wrong while parsing the document. This is usually
[an error occurred while processing this directive],
but it can be set to anything with this directive.





 
 

Example:



 

<!--#config errmsg="[It's
broken, dude]" -->





 
 

sizefmt



 

Sets the format used to display file sizes. You can set
the value to bytes to display the exact
file size in bytes, or abbrev to display
the size in KB or MB.





 
 

Example:



 

<!--#config sizefmt="bytes"
-->





 
 

timefmt



 

Sets the format used to display times. The format of the
value is the same as is used in the strftime
function used by C (and Perl) to display dates, shown in the following
table.





 
 

%%



 

PERCENT





 
 

%a



 

Day of the week abbreviated.





 
 

%A



 

Day of the week





 
 

%b



 

Month abbreviated.





 
 

%B



 

Month





 
 

%c



 

ctime format: Sat
Nov 19 21:05:57 1994





 
 

%d



 

Numeric day of the month





 
 

%e



 

DD





 
 

%D



 

MM/DD/YY





 
 

%h



 

Month abbreviated.





 
 

%H



 

Hour, 24-hour clock, leading zeros





 
 

%I



 

Hour, 12-hour clock, leading zeros





 
 

%j



 

Day of the year





 
 

%k



 

Hour





 
 

%l



 

Hour, 12-hour clock





 
 

%m



 

Month number, starting with 1





 
 

%M



 

Minute, leading zeros





 
 

%n



 

Newline





 
 

%o



 

Ornate day of month--1st, 2nd, 25th, and so on





 
 

%p



 

AM or PM





 
 

%r



 

Time format: 09:05:57 PM





 
 

%R



 

Time format: 21:05





 
 

%S



 

Seconds, leading zeros





 
 

%t



 

Tab





 
 

%T



 

Time format: 21:05:57





 
 

%U



 

Week number; Sunday as first day of week





 
 

%w



 

Day of the week, numerically; Sunday == 0





 
 

%W



 

Week number; Monday as first day of week





 
 

%x



 

Date format: 11/19/94





 
 

%X



 

Time format: 21:05:57





 
 

%y



 

Year (2 digits)





 
 

%Y



 

Year (4 digits)





 
 

%Z



 

Time zone in ASCII, such as PST






echo



 

Displays
any one of the include variables, listed below. Times are displayed
in the time format specified by timefmt.
The variable to be displayed is indicated with the var
attribute.






DATE_GMT



 

The current date in Greenwich Mean Time.






DATE_LOCAL



 

The current date in the local time zone.






DOCUMENT_ NAME



 

The filename (excluding directories) of the document requested
by the user.






DOCUMENT_ URI



 

The (%-decoded) URL path of the document requested by
the user. Note that in the case of nested include files, this is not
the URL for the current document.






LAST_ MODIFIED



 

The last modification date of the document requested by
the user.






exec



 

Executes
a shell command or a CGI program, depending on the parameters provided.
Valid attributes are cgi and cmd.





 
 

cgi



 

The URL of a CGI program to be executed. The URL needs
to be a local CGI, not one located on another machine. The CGI program
is passed the QUERY_STRING and PATH_INFO
that were originally passed to the requested document, so the URL specified
cannot contain this information. You should really use include
virtual instead of this directive.





 
 

cmd



 

A shell command to be executed. The results will be displayed
on the HTML page.






fsize



 

Displays
the size of a file specified by either the file
or virtual attribute. Size is displayed
as specified with the sizefmt directive.





 
 

file



 

The path (filesystem path) to a file, either relative
to the root if the value starts with /,
or relative to the current directory if not.





 
 

virtual



 

The relative URL path to a file.






flastmod



 

Displays
the last modified date of a file. The desired file is specified as with
the fsize directive.






include



 

Include
the contents of a file. The file is specified with the file
and virtual attributes, as with fsize
and flastmod. If the file specified is a
CGI program and IncludesNOEXEC is not set,
the program will be executed and the results displayed. This is to be
used in preference to the exec directive.
You can pass a QUERY_STRING with this directive,
which you cannot do with the exec directive.






printenv




 

Displays all of existing variables. There are no attributes.


Example: <!--#printenv -->






set




 

Set the value of a variable. Attributes are var
and value.


Example: <!--#set var="animal"
value="cow" -->







Note -
All defined CGI environment variables are also allowed as
include variables.

Note -
In your configuration files (or in .htaccess), you
can specify Options IncludesNOEXEC to disallow the
exec directive, as this is the least secure of the
SSI directives. Be especially cautious when Web users are able to create content
(like a guestbook or discussion board) and these options are
enabled!

These variables can be used elsewhere with some of the following
directives.



Flow Control
Using the
variables set with the set directive and the various
environment variables and include variables, there is a limited flow control
syntax that can be used to generate a certain amount of dynamic content on
server-parsed pages.The syntax of the
if/else functions is as
follows:



<!--#if expr="test_condition" -->
<!--#elif expr="test_condition" -->
<!--#else -->
<!--#endif -->

expr can be a string, which is
considered true if non-empty, or a variety of comparisons between two strings.
Available comparison operators are =,
!=, <,
<=, >, and
>=. If the second string has the format
/string/, the strings are compared with regular
expressions. Multiple comparisons can be strung together with
&& (AND) and
|| (OR). Any text
appearing between the
if/elif/else
directives will be displayed on the resulting page. An example of such a flow
structure follows:



<!--#set var="agent" value="$HTTP_USER_AGENT" -->
<!--#if expr="$agent = /Mozilla/" -->
Mozilla!
<!--#else -->
Something else!
<!--#endif -->

This code will display "Mozilla!" if you are using a
browser that passes Mozilla as part of its USER_AGENT
string, and "Something else!" otherwise.





Red Hat® Linux 6 Unleashed










Chapter 9: Apache Server





Previous
ChapterNext
Chapter










Sections in this Chapter:








Server
Installation





CGI and SSI






Runtime
Server Configuration Settings





Starting
and Stopping the Server






Virtual
Hosting





Configuration
File Listings

















 

Previous
SectionNext
Section





© Copyright Macmillan USA. All rights reserved.

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • teen-mushing.xlx.pl
  • Wątki
    Powered by wordpress | Theme: simpletex | © Lemur zaprasza