Search code examples
perlnginxfastcgicatalyst

nginx and catalyst configuration


I am having trouble deploying a Catalyst application using nginx and fastcgi. I attempting to do this under ubuntu 12.04.

I have successfully configured nginx to serve static content from my app's /root subdirectory. However, when I try to any of my dynamic urls, I get a 404 error in my application's error log saying the (unmapped) url is not found, which leads me to believe that nginx is attempting to serve the request akin to a static page instead of sending it to my Catalyst app.

To restate, hitting 'localhost:3001/root/static.html' results in the static content being successfully displayed in the browser, but hitting 'localhost:30001/expense/editor' results the following error:

"GET /expense/editor HTTP/1.1" 404

(where '/expense/editor' is a path in my app, one that I can successfully access when running the built-in Catalyst development server).

I am launching the Catalyst app as:

> perl script/budgetweb_fastcgi.pl -l localhost:3003

I also tried running /etc/init.d/fcgiwarp. I am unclear if I need to run a separate fastcgi wrapper, or if the perl script above is my fastcgi wrapper. I edited fcgiwrap to use TCP sockets (127.0.0.1:3003), which then prevented me from running both /etc/init.d/fcgiwrap and script/budgetweb_fastcgi.pl at the same time, since they both use the same socket. So I'm guessing I'm only supposed to use the Catalyst script? Also, when running fcgiwrap, I get 502 "bad gateway" errors when attempting to access static content.

Any help, or pointers to help, will be much appreciated. So far I have looked at the following pages (among others; StackOverflow will only allow me to post two links):

Catalyst wiki
HOWTO: Deploy a Catalyst application using FastCGI and nginx

Here is my nginx config file for the server:

server {
       listen       3001;
       server_name  budgetweb.com;
       root     /local/www/money/budgetweb;

       location /root {
           add_header Cache-control public;
       root /local/www/money/budgetweb/;
       }

       location / {
          access_log    /local/www/money/budgetweb/logs/access.log;
          error_log /local/www/money/budgetweb/logs/error.log;
          index  index.html index.htm index.pl;
      try_files $uri =404;
      gzip off;

      fastcgi_pass  localhost:3003;
          fastcgi_index index.pl;

          include /etc/nginx/fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  /local/www/money/budgetweb$fastcgi_script_name;
      fastcgi_param  SCRIPT_NAME /;
      fastcgi_param  PATH_INFO $fastcgi_script_name;
        } 

       # Disable gzip (it makes scripts feel slower since they have to complete
       # before getting gzipped)
       gzip off;

#       include         /etc/nginx/fcgiwrap.conf;
}

Solution

  • The fastcgi.pl script included with Catalyst is your FastCGI wrapper. All you should have to do is start that on a socket, then point your webserver to that socket and everything should pass through. The only thing you'll want to do for a production system is create a start/stop script that will start and stop your application on startup and shutdown. The start command will look pretty much like what you ran above (you may want to add a '-d' flag to daemonize it.)

    On your webserver configuration, configuring '/' to point to your application should be fine. You might try removing the 'index', 'try_files', and 'fastcgi_index' configuration lines, that might be causing nginx to try and statically serve the content instead of passing the request to your application.