Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This question springs from a recent conversation I had with btrott and his rather excellent STAMP script.

Imagine if you will a typical Apache box, it's got one shared CGI-BIN, or mod_perl folder that is shared by all the various virtual domains on the box. Each domain looks different, so I want to make the script look different too.

QUESTION how do you neatly configure the script for all the various domains?

You can ask CGI to give you the virtual host name, and then check to see if there is a configuration file for it, if not you read a default one. This is what I tried, see code below. It works okay, but you'll end up with a folder full of config files, one per script per host, which may get messy.

So my question is, how do you neatly write CGI/mod_Perl script so that they can be shared on a mass-hosting Apache box, and yet maintain their own look'n'feel (via config), and what have you.

my $server = "localhost"; # Default host my $domain = ".company.com"; # Default domain my $conf_loc = "/someplace"; # Where config files live $server = $q->virtual_host() if $q->virtual_host(); # Where are +we? $server .= $domain unless ($server =~ /[$domain]$/i); # Need a do +main? if ($server =~ /^([-\w\.]+)$/) { # clean it $server = lc($1); chdir $conf_loc or error($q, qq(Unable to locate configuration fol +der $conf_loc)); $CFG_FILE = $server . ".$CFG_FILE" if ($server && -R "$server.$CFG +_FILE"); # If there is a specific file then use it }

$CFG_FILE is what STAMP expects to use, and error is it's error handling routine.

This is an addition to STAMP, I used for ilustration purposes. STAMP is cool, get it your self from it's author.

As ever thanks in advance.


In reply to Running Perl scripts from a single CGI-BIN, on a multiple-virtual hosting server by ajt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-20 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found