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
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning
Learn benefits of Simpana software.
View the Gartner Video



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




Recent comments
18 hours 34 min ago
23 hours 41 min ago
1 day 6 hours ago
1 day 7 hours ago
1 day 10 hours ago
1 day 10 hours ago
1 day 14 hours ago
1 day 14 hours ago
1 day 14 hours ago
1 day 16 hours ago