Running HTML::Mason With nginx And FastCGI
Running HTML::Mason With nginx And FastCGIThis article is a step by step guide to install the HTML::Mason module to use with the ngingx web server and FastCGI. It has been tested in Debian (lenny), but it should be very similar with Ubuntu and other debian based distros.
Installing a minimal running serverFirst of all we will install a minimal server with nginx and FastCGI. I made basic scripts to make it run. Later we can customize those scripts.
Install nginxNow we install nginx and get it working. It is assumed there is no other web server up in the host. Everything will be installed by default. apt-get install nginx Let's see if it does work telnetting to port 80.
/etc/init.d/nginx start
Install FastCGIapt-get install libcgi-fast-perl libio-all-perl
Install HTML::MasonHTML::Mason is supossed to need apache2 to run, so it will download and install it. We will get rid of it later.
apt-get install libhtml-mason-perl Hopefully, we now have HTML::Mason installed and no apache traces. Make sure nginx is still working checking it still answers on port 80.
Configure FastCGIWe need a FastCGI server running so it can execute HTML::Mason code. This script will download all the configuration and init files. We must run it as root. Please take a look at it before running it. It downlads and copies some files from github. It could be dangerous to your server.
wget http://github.com/frankiejol/mason-fcgi/raw/master/download.sh It is very important to change the server_name option in /etc/nginx/sites-available/mason to the real name of the server. Localhost won't work. Then modify the %SITES variable in /var/www/mason/mason_fcgi.pl.
Running Mason codeFinally let's create a simple Mason page.
mkdir /var/www/site1 Then let's start the service. A 4 should appear if you connected the site with your browser.
/etc/init.d/nginx restart
Customizing the serverRight now we have a nginx+FastCGI powered Mason server. All the configuration files and scripts can be found in my github repository.
nginxnginx configuration is in /etc/nginx/sites-available/mason. The location can be modified to suite your need. Notice there are two rewrite lines because Mason can't handle directories properly. So when the request looks like a directory, an index.html postfix is added.
FastCGIThe FastCGI startup script is /var/www/mason/mason_fcgi.pl. A bunch of arguments can be supplied.
/var/www/mason/mason_fcgi.pl --help There is a section to add the loading of Perl modules and global variables. This is the default code: {
package HTML::Mason::Commands;
# use My::Own::Module;
# use Data::Dumper;
# anything you want available to components
use vars(qw($DBH %stash));
}
Running multiple FastCGI sitesThe FastCGI daemon is run from /etc/init.d/fcgi. This script loads the configuration from /etc/default/fcgi. If you need more FastCGI servers for different sites. Just copy the init script to another name and call the config file the same. The init script will load a file in /etc/default with the same basename as itself.
Links
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com
Red Hat Virtual Experience - a free virtual event. Dec. 9th




![Creative Commons Attribution License [Creative Commons Attribution License]](http://creativecommons.org/images/public/somerights20.gif)



Recent comments
20 hours 26 min ago
1 day 2 min ago
1 day 2 hours ago
1 day 10 hours ago
1 day 12 hours ago
1 day 14 hours ago
1 day 15 hours ago
1 day 15 hours ago
1 day 18 hours ago
1 day 23 hours ago