Linode Library Home
Linode Library RSS Feed
Home :: Web Servers :: Nginx :: Perl-FastCGI
Print View View Source

Nginx and Perl-FastCGI on Arch Linux

Published: by


This document is an older, unmaintained guide. There may be a new guide available for this software.

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 capable of handling dynamically generated content. The process described in this document centers on the deployment of a FastCGI wrapper for CGI. This makes it possible to deploy all dynamic content that communicates using the CGI protocol. Typically this kind of script is written in Perl, but other CGI scripts will be compatible with this solution.


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 command to install the required packages from the Arch Linux repositories:

pacman -Sy
pacman -S pacman
pacman -S nginx fcgi fcgiwrap spawn-fcgi

Edit the /etc/rc.conf file, adding "nginx" and "fcgiwrap" to the "DEAMONS=" line as shown in the following excerpt:

File excerpt:/etc/rc.conf

DAEMONS=(syslog-ng network netfs crond sshd ntpd nginx fcgiwrap)

Configure the FastCGI Wrapper

Now, edit the /etc/conf.d/fcgiwrap file to resemble the following example:



Issue the following command to start the FastCGI wrapper for the first time:

/etc/rc.d/fcgiwrap start

Configure Virtual Hosting

Create directories for your web content and logs by issuing the following commands. Be sure to replace "" with your domain name.

mkdir -p /srv/http/
mkdir /srv/http/

Issue the following commands to create nginx virtual host directories:

mkdir /etc/nginx/conf/sites-available
mkdir /etc/nginx/conf/sites-enabled

Create a virtual host configuration file for your site. Be sure to replace "" with your domain name in the following example configuration.


server {
    listen   80;
    access_log /srv/http/;
    error_log /srv/http/;

    location / {
        root   /srv/http/;
        index  index.html index.htm;

    location ~ \.cgi$ {
        gzip off;
        include fastcgi_params;
        fastcgi_index index.cgi;
        fastcgi_param  SCRIPT_FILENAME  /srv/http/$fastcgi_script_name;

This example assumes that all CGI scripts will end with the characters .cgi. If your scripts have some other extension (e.g. .pl or .plx) modify the example to support that. If you want nginx to use the CGI script as an index page, add index.cgi to the index line of the "location /" block.

Issue the following commands to enable your new virtual host:

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

Edit the file /etc/nginx/conf/nginx.conf, inserting the line "include /etc/nginx/conf/sites-enabled/*;" at the start of the "http {" block, as shown in the following file excerpt:

File excerpt:/etc/nginx/conf/nginx.conf

http {

    include /etc/nginx/conf/sites-enabled/*;

Issue the following command to start nginx:

/etc/rc.d/nginx start

Test Perl with FastCGI

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



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/http/

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.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Sharon Campbell on Monday, October 7th, 2013 (r3824).