nginxdancerplackstarman

An explanation of the nginx/starman/dancer web stack


I've been doing web-programming for a while now and am quite familiar with the LAMP stack. I've decided to try playing around with the nginx/starman/dancer stack and I'm a bit confused about how to understand, from a high-level, how all the pieces relate to each other. Setting up the stack doesn't seem as straight forward as setting up the LAMP stack, but that's probably because I don't really understand how the pieces relate.

I understand the role nginx is playing - a lightweight webserver/proxy - but I'm confused about how starman relates to pgsi, plack and dancer.

I would appreciate a high-level breakdown of how these pieces relate to each other and why each is necessary (or not necessary) to get the stack setup. Thanks!


Solution

  • I've spent the last day reading about the various components and I think I have enough of an understanding to answer my own question. Most of my answer can be found in various places on the web, but hopefully there will be some value to putting all the pieces in one place:

        sudo apt-get install nginx
        sudo apt-get install build-essential curl
        sudo cpan App::cpanminus
        sudo cpanm Starman
        sudo cpanm Task::Plack
        sudo apt-get install libdancer-perl
    
    cd
    dancer -a mywebapp
    sudo plackup -s Starman -p 5001 -E deployment --workers=10 -a mywebapp/bin/app.pl
    

    Now you will have a starman server running your Dancer application on port 5001. To make nginx send traffic to the server you have to modify

    /etc/nginx/nginx.conf
    and add a rule something like this to the http section:

            server {
                   server_name permanentinvesting.com
                   listen 80;
    
                    location /css/ {
                      alias /home/ubuntu/mywebapp/public/css/;
                      expires 30d;
                      access_log off;
                    }
    
    
    
                   location / {
                      proxy_pass        http://localhost:5001;
                      proxy_set_header  X-Real-IP  $remote_addr;
                    }
    
            }
    
    

    The first location rule specifies that nginx should handle static content in the /css directory by getting it from

    /home/ubuntu/mywebapp/public/css/
    . The second location rule says that traffic to the webserver on port 80 should be sent to the Starman server to handle. Now we just need to start nginx:

    sudo service nginx start