Web Server Notes

Author:

Dimitry Dukhovny

Using Apache2 with SSL as a Proxy for an application service

Your web server, serverA, stands in front of your app server, serverB. It serves two distinct services as URIone and URItwo.

/etc/httpd/conf.d/020-ssl.conf or /etc/apache2/sites-available/020-ssl.conf
 1# Make sure we use SSL/TLS...
 2LoadModule ssl_module modules/mod_ssl.so
 3# ...and listen on the expected port for HTTPS
 4Listen 443
 5<VirtualHost serverA:443>
 6        # Activate the features we will use
 7        RewriteEngine On
 8        SSLPRoxyEngine On
 9        SSLProxyCheckPeerCN Off
10        # Starting in Apache 2.5...
11        SSLProxyCheckPeerName Off
12        ProxyRequests Off
13        RequestHeader unset Accept-Encoding
14        RequestHeader unset Authorization
15        <Location /URIone>
16                RewriteRule ^/URIone$ /URIone/ [R]
17                ProxyPass https://serverB/URIone keepalive=on
18                ProxyPassReverse https://serverB/URIone
19                ProxyPassReverseCookieDomain serverB serverA
20        </Location>
21        <Location /URItwo>
22                RewriteRule ^/URItwo$ /URItwo/ [R]
23                ProxyPass https://serverB/URItwo keepalive=on
24                ProxyPassReverse https://serverB/URItwo
25                ProxyPassReverseCookieDomain serverB serverA
26        </Location>
27        # Text substitutions for generated links
28        Substitute "s|http://serverB|https://serverA|n"
29        Substitute "s|https://serverB|https://serverA|n"
30        Substitute "s|https://serverB:443|https://serverA|n"
31        # Deal with MSIE
32        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
33        # Log appropriately
34        CustomLog logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
35</VirtualHost>

Receiving uploads with a web form using PERL CGI

This script is a hodgepodge of simple solutions from all over the Internet. The original author is lost to time, but I suspect it was an early recipe from Rich “DrBacchus” Bowen’s Apache Cookbook.

Download upload.cgi

upload.cgi
 1#!/usr/bin/perl -wT
 2
 3use strict;
 4use CGI;
 5use CGI::Carp qw ( fatalsToBrowser );
 6use File::Basename;
 7
 8$CGI::POST_MAX = 1024 * 1024 * 1024 * 5;
 9my $safe_filename_characters = "a-zA-Z0-9_.-";
10my $upload_dir = "/var/www/inbound";
11
12my $query = new CGI;
13my $filename = $query->param("inbound");
14my $email_address = $query->param("email_address");
15
16if ( !$filename )
17{
18print $query->header ( );
19print "There was a problem uploading. Maybe it is bigger than " . $CGI::POST_MAX . ".";
20exit;
21}
22
23my ( $name, $path, $extension ) = fileparse ( $filename, '..*' );
24$filename = $name . $extension;
25$filename =~ tr/ /_/;
26$filename =~ s/[^$safe_filename_characters]//g;
27
28if ( $filename =~ /^([$safe_filename_characters]+)$/ )
29{
30$filename = $1;
31}
32else
33{
34die "Filename contains invalid characters";
35}
36
37my $upload_filehandle = $query->upload("inbound");
38
39open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
40binmode UPLOADFILE;
41
42while ( <$upload_filehandle> )
43{
44print UPLOADFILE;
45}
46
47close UPLOADFILE;
48
49print $query->header ( );
50print <<END_HTML;
51<!DOCTYPE html>
52<html>
53<head>
54<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55<title>Thanks!</title>
56<style type="text/css">
57img {border: none;}
58</style>
59</head>
60<body>
61<p>Your filename: $filename</p>
62</body>
63</html>
64END_HTML