Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
192 lines (141 sloc) 6.59 KB
deprecated author description keywords license alias modified modified_by published title
name email
Serve dynamic websites and applications with the lightweight nginx web server and Perl-FastCGI on Ubuntu 10.10 (Maverick).
nginx,fastscgi perl,nginx ubuntu 10.10,nginx fastcgi,nginx perl
Monday, October 8th, 2012
Friday, October 15th, 2010
Nginx and Perl-FastCGI on Ubuntu 10.10 (Maverick)

The nginx web server is a fast, lightweight server designed to efficiently handle the needs of both low and high traffic websites. Although commonly used to serve static content, it's quite capable of handling dynamic pages as well. This guide will help you get nginx up and running with Perl and FastCGI on your Ubuntu 10.10 (Maverick) Linux VPS.

It is assumed that you've already followed the steps outlined in our getting started guide. These steps should be performed via a root login to your Linode over SSH.

Set the Hostname

Before you begin installing and configuring the components described in this guide, please make sure you've followed our instructions for setting your hostname. Issue the following commands to make sure it is set properly:

hostname -f

The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

Install Required Packages

Issue the following commands to update your system and install the nginx web server and FastCGI components:

apt-get update
apt-get upgrade
apt-get install nginx fcgiwrap spawn-fcgi

Configure DNS

Create an "A" record pointing your domain name to your Linode's IP address. If you're using the Linode DNS Manager interface, please refer to our Linode DNS manager guide for instructions.

Configure Virtual Hosting

Create Directories

In this guide, the domain "" is used as an example site. You should substitute your own domain name in the configuration steps that follow. First, create directories to hold content and log files:

mkdir -p /srv/www/
mkdir /srv/www/
chown -R www-data:www-data /srv/www/

UNIX Sockets Configuration Example

Next, you'll need to define the site's virtual host file. This example uses a UNIX socket to connect to fcgiwrap. Be sure to change all instances of "" to your domain name.

{: .file } /etc/nginx/sites-available/ : ~~~ nginx server { listen 80; server_name; access_log /srv/www/; error_log /srv/www/; root /srv/www/;

    location / {
        index  index.html index.htm;

    location ~ \.pl$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /srv/www/$fastcgi_script_name;

TCP Sockets Configuration Example

Alternately, you may wish to use TCP sockets instead. If so, modify your nginx virtual host configuration file to resemble the following example. Again, make sure to replace all instances of "" with your domain name.

{: .file } /etc/nginx/sites-available/ : ~~~ nginx server { listen 80; server_name; access_log /srv/www/; error_log /srv/www/; root /srv/www/;

    location / {
        index  index.html index.htm;

    location ~ \.pl$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /srv/www/$fastcgi_script_name;

If you elected to use TCP sockets instead of UNIX sockets, you'll also need to modify the fcgiwrap init script. Look for the following section in the /etc/init.d/fcgiwrap file:

{: .file-excerpt } /etc/init.d/fcgiwrap : ~~~ # FCGI_APP Variables FCGI_CHILDREN="1" FCGI_SOCKET="/var/run/$NAME.socket" FCGI_USER="www-data" FCGI_GROUP="www-data" ~~~ Change it to match the following excerpt:

{: .file-excerpt } /etc/init.d/fcgiwrap : ~~~ # FCGI_APP Variables FCGI_CHILDREN="1" FCGI_PORT="8999" FCGI_ADDR="" FCGI_USER="www-data" FCGI_GROUP="www-data" ~~~

Enable the Site

Issue the following commands to enable the site:

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/

Start nginx and fcgiwrap by issuing the following commands:

/etc/init.d/fcgiwrap start
/etc/init.d/nginx start

Test Perl with FastCGI

Create a file called "" in your site's "public_html" directory with the following contents:

{: .file } /srv/www/ : ~~~ perl #!/usr/bin/perl

print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Perl Environment Variables</title></head>
<h1>Perl Environment Variables</h1>

foreach $key (sort(keys %ENV)) {
    print "$key = $ENV{$key}<br>\n";

print "</body></html>";

Make the script executable by issuing the following command:

chmod a+x /srv/www/

When you visit in your browser, your Perl environment variables should be shown. Congratulations, you've configured the nginx web server to use Perl with FastCGI for dynamic content!

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Something went wrong with that request. Please try again.