NGINX和Lua脚本:在content_by_lua中有条件使用

时间:2015-12-02 15:25:32

标签: nginx lua openresty

我正在尝试创建一个条件content_by_lua脚本,其中的内容应该只在一个条件下由lua设置。

示例:

nginx.conf

location / {
        content_by_lua_file  /nginx/lua/nginx.lua;

        root   /nginx/www;
        index  index.html;

        location ~* \.(?:ico|css|js|gif|jpe?g|png|woff|ttf)$ {
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }
    }

nginx.lua

if condition then
    ngx.header["Content-type"] = "text/html"
    ngx.say('<H1>Hello World.</H1>');
    ngx.exit(0)
else
    -- serve the original content (index.html)
end 

问题是 - 在nginx下的lua脚本在同一路由中不支持2内容指令,我可以做一个解决方法吗?

当条件为false时使用当前用法我希望显示index.html但是接收空白页面

1 个答案:

答案 0 :(得分:1)

您可以拨打roll_btn.addEventListener(MouseEvent.CLICK, rollDice); function rollDice(event:MouseEvent):void { var die1:uint = Math.floor(Math.random() * 6); var die2:uint = Math.floor(Math.random() * 6); var diceTotal:uint = die1 + die2; die1_txt.text = die1.toString(); die2_txt.text = die2.toString(); status_txt.text = "You rolled "+diceTotal; // ... } 来拨打内部电话。

<强> nginx.conf

ngx.exec

<强> nginx.lua

location / {
    content_by_lua_file  /nginx/lua/nginx.lua;

    root   /nginx/www;
    index  index.html;

    location ~* \.(?:ico|css|js|gif|jpe?g|png|woff|ttf)$ {
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

location /default_index {
    root   /nginx/www;
    index  index.html;
}