nginx/starman/dancer Web堆栈的说明 [英] An explanation of the nginx/starman/dancer web stack

查看:86
本文介绍了nginx/starman/dancer Web堆栈的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了一段时间的Web编程,并且对LAMP堆栈非常熟悉.我决定尝试使用nginx/starman/dancer堆栈,但对于如何从高层次理解所有部分之间的相互联系,我有些困惑.设置堆栈似乎不像设置LAMP堆栈那样简单,但这可能是因为我不太了解各个部分之间的关​​系.

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.

我了解nginx扮演的角色-一个轻量级的Web服务器/代理-但是我对starman与pgsi,plack和舞者的关系感到困惑.

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!

推荐答案

我花了最后一天阅读有关各种组件的信息,我认为我有足够的理解力可以回答我自己的问题.我大部分的答案都可以在网上的不同地方找到,但希望将所有内容放在一个地方会有一定的价值:

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:

  • Nginx:要理解的栈中第一个也是最显而易见的部分是nginx. Nginx是一种轻量级的Web服务器,可以替代无处不在的Apache Web服务器. Nginx也可以充当代理服务器.它的使用量迅速增长,目前约有 10%. Nginx的一个关键优势是它是异步的并且是事件驱动的,而不是创建一个进程线程来处理每个连接.从理论上讲,这意味着nginx能够处理大量连接而无需使用大量系统资源.
  • PSGI: PSGI 是一个协议(以便将其与协议的特定实现(例如Plack)区分开来.据我所知,创建PSGI的主要动机是,首次创建Apache时,没有原生支持使用Perl编写的脚本来处理请求.使用mod_cgi将此功能附加到Apache.要测试Perl应用程序,您必须运行整个Web服务器,因为该应用程序在Web服务器中运行.相比之下,PSGI提供了一个协议,网络服务器可以通过该协议与以例如Perl.这样做的好处之一是,独立于Web服务器测试Perl服务器要容易得多.另一个好处是,一旦构建了应用程序服务器,就可以很容易地切换到兼容PSGI的其他Web服务器进行测试,以提供最佳性能.
  • Plack:这是PSGI协议的一种特殊实现,它提供了与PSGI兼容的Web服务器和Perl应用程序服务器之间的粘合. Plack相当于Perl的Ruby's Rack.
  • Starman:与PSGI协议兼容的基于Perl的Web服务器.我有一个困惑,就是为什么我想同时使用Starman和Nginx,但值得庆幸的是,这个问题是 Dancer :Perl的Web应用程序框架.相当于Ruby on Rails的一种.或更准确地说,相当于Sinatra for Ruby(不同之处在于Sinatra是一个极简主义的框架,而Ruby on Rails是一个更全面的Web框架).作为处理过PHP且以前从未真正使用过Web框架的人,我对此与服务堆栈之间的关系感到有些困惑. Web框架的重点是抽象出Web应用程序中经常执行的常见任务,例如将数据库查询转换为Web应用程序中的对象/数据结构.
  • Nginx: The first and most obvious piece of the stack to understand is nginx. Nginx is a lightweight webserver that can act as a replacement for the ubiquitous Apache webserver. Nginx can also act as a proxy server. It has been growing rapidly in its use and currently serves about 10% of all web domains. One crucial advantage of nginx is that it is asynchronous and event-driven instead of creating a process thread to handle each connection. In theory this means that nginx is able to handle a large number of connections without using a lot of system resources.
  • PSGI: PSGI is a protocol (to distinguish it from a particular implementation of the protocol, such as Plack). The main motivation for creating PSGI, as far as I can gather, is that when Apache was first created there was no native support for handling requests with scripts written in e.g., Perl. The ability to do this was tacked on to Apache using mod_cgi. To test your Perl application, you would have to run the entire webserver, as the application ran within the webserver. In contrast, PSGI provides a protocol with which a webserver can communicate with a server written in e.g. Perl. One of the benefits of this is that it's much easier to test the Perl server independently of the webserver. Another benefit is that once an application server is built, it's very easy to switch in different PSGI-compatible webservers to test which provides the best performance.
  • Plack: This is a particular implementation of the PSGI protocol that provides the glue between a PSGI-compatible webserver and a perl application server. Plack is Perl's equivalent of Ruby's Rack.
  • Starman: A perl based webserver that is compatible with the PSGI protocol. One confusion I had was why I would want to use both Starman and Nginx at the same time, but thankfully that question was answered quite well here on Stackoverflow. The essence is that it might be better to let nginx serve static files without requiring a perl process to do that, while also allowing the perl application server to run on a higher port.
  • Dancer: A web application framework for Perl. Kind of an equivalent of Ruby on Rails. Or to be more precise, an equivalent of Sinatra for Ruby (the difference is that Sinatra is a minimalist framework, whereas Ruby on Rails is a more comprehensive web framework). As someone who dealt with PHP and hadn't really used a web framework before, I was a bit confused about how this related to the serving stack. The point of web frameworks is they abstract away common tasks that are very frequently performed in web applications, such as converting database queries into objects/data structures in the web application.

安装(在ubuntu上):

Installation (on ubuntu):


    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
    

    现在,您将拥有一个在端口5001上运行Dancer应用程序的starman服务器.要使nginx将流量发送到该服务器,您必须修改

    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

    并将类似如下的规则添加到http部分:

    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;
                    }
    
            }
    
    

    第一个位置规则指定nginx应该通过从

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

    /home/ubuntu/mywebapp/public/css/

    获取它来处理/css目录中的静态内容.第二个位置规则说,到端口80的Web服务器的流量应发送到Starman服务器进行处理.现在我们只需要启动nginx:

    . 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
    

    这篇关于nginx/starman/dancer Web堆栈的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆