Vij*_*ati 32 nginx plack starman dancer
我已经做了一段时间的网络编程,并且对LAMP堆栈非常熟悉.我决定尝试玩弄nginx的/接龙/舞者堆栈和我有点困惑如何理解,从一个高层次,所有的部分是如何相互关联的.设置堆栈似乎并不像设置LAMP堆栈那样简单,但这可能是因为我并不真正了解这些部分是如何相关的.
我理解nginx正在扮演的角色 - 一个轻量级的网络服务器/代理 - 但我对starman与pgsi,plack和舞者的关系感到困惑.
我将非常感谢这些部分如何相互关联以及为什么每个部分都需要(或不必要)来获得堆栈设置的高级细分.谢谢!
Vij*_*ati 49
我花了最后一天阅读各种组件,我认为我有足够的理解来回答我自己的问题.我的大部分答案都可以在网上的不同地方找到,但希望将所有部分放在一个地方有一些价值:
Dancer:Perl的Web应用程序框架.Ruby on Rails的等价物.或者更确切地说,相当于Sinatra for Ruby(区别在于Sinatra是一个极简主义框架,而Ruby on Rails是一个更全面的Web框架).作为处理PHP并且以前没有真正使用过Web框架的人,我对这与服务堆栈的关系有点困惑.Web框架的重点是它们抽象出在Web应用程序中经常执行的常见任务,例如将数据库查询转换为Web应用程序中的对象/数据结构.
安装(在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向服务器发送流量,您必须修改
/etc/nginx/nginx.conf并在http部分添加类似这样的规则:
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应该通过获取它来处理/ css目录中的静态内容
/home/ubuntu/mywebapp/public/css/.第二个位置规则表示应将端口80上的Web服务器的流量发送到Starman服务器进行处理.现在我们只需要启动nginx:
sudo service nginx start
您的答案到目前为止是正确的,但最好通过以下方式设置nginx:
server {
listen 80;
server_name foo.example.com;
location / {
# Serve static files directly:
if (-f $request_filename) {
expires 30d;
break;
}
# Pass on other requests to Dancer app
proxy_pass_header Server;
proxy_pass http://localhost:5001/;
}
}
Run Code Online (Sandbox Code Playgroud)
这使得nginx服务于所有静态文件(JavaScript和图像)而不仅仅是css.
这个例子取自2011 Perl Dancer Advent :)
小智 5
来自 nginx wiki:
“IfIsEvil ...指令 if 在位置上下文中使用时出现问题,在某些情况下,它不会执行您期望的操作,而是完全不同的操作。在某些情况下,它甚至会出现段错误。通常最好避免如果可以的话……”
更好的设置是:
server {
listen 80;
server_name foo.example.com;
location / {
# Checks the existence of files and uses the first match
try_files $uri $uri/ @dancer;
}
location @dancer {
# Pass on other requests to Dancer app
proxy_pass_header Server;
proxy_pass http://localhost:5001/;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7026 次 |
| 最近记录: |