AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[lua](server)

Martin Hope
Leandro Moreira
Asked: 2020-09-10 04:03:27 +0800 CST

在body_filter_by_lua_block期间是否可以避免lua nginx上的分块传输?

  • 0

假设我们要更改来自上游的响应,我们可以做的是在body_filter_by_lua_block阶段使用 Lua+nginx,这是其中的一个片段。

  server {
    listen 8181;
    location /media {
        alias /media/;
    }
  }

  server {
    listen 8080;

    location /media {
        proxy_pass http://localhost:8181;

        # we need to keep this url since we're going to rewrite
        set_by_lua_block $original_uri { return ngx.var.uri }

        # when the Lua code may change the length of the response body
        header_filter_by_lua_block { ngx.header.content_length = nil }

        # removing (rewriting) the filters
        rewrite_by_lua_block {
          local uri = ngx.re.sub(ngx.var.uri, "^/media/(.*)/hls/(.*)$", "/media/hls/$2")
          ngx.req.set_uri(uri)
        }

        # applying the bandwidth min filter
        # but we can use the ngx.var.original_uri to build/select the filters
        body_filter_by_lua_block {
          local modified_manifest = filtering(ngx.arg[1])
          ngx.arg[1] = modified_manifest
          ngx.arg[2] = true
        }
    }

这工作得很好!但问题是,这种方式响应将使用分块传输,有些客户端无法处理分块响应,你知道我该如何克服吗?

nginx openresty lua
  • 1 个回答
  • 705 Views
Martin Hope
Leos Literak
Asked: 2020-06-04 08:46:36 +0800 CST

将 LUA 构建为动态 Nginx 模块

  • 0

我发现要将 LUA 与 Nginx 一起使用,我需要:

  • 使用 OpenResty 平台:https ://openresty.org/en/installation.html
  • 支付 getpagespeed 订阅以获取模块 RPM
  • 从源代码构建带有 LUA 模块的 Nginx,例如https://tarunlalwani.com/post/building-nginx-with-lua/

我想知道如何构建模块本身,然后将其加载到打包的 Nginx 中。我不愿意构建 Nginx,因为这意味着我会丢失包更新。我怎样才能做到这一点?

nginx lua
  • 1 个回答
  • 430 Views
Martin Hope
Madhur Ahuja
Asked: 2016-12-27 10:31:19 +0800 CST

NGINX + Lua:根据上游响应头设置缓存键

  • 1

我正在尝试使用上游响应标头字段值来控制缓存键。有问题的标题字段在Common-Api下面的配置中。

我不断得到nginx: [emerg] unknown "ck" variable。知道我做错了什么吗?

 location ~^/(deals-new)/ {
            set $no_cache 0;
            proxy_cache helpchat_cache;

            proxy_cache_min_uses 1;
            #proxy_cache_valid  200 302 10m;
            proxy_cache_valid  404 1m;
            #proxy_cache_lock on;
            proxy_cache_use_stale error timeout updating invalid_header http_500 http_502 http_503 http_504;

            client_max_body_size 25M;
            #auth_basic "closed website";
            #auth_basic_user_file /etc/nginx/htpasswd;
            root   /usr/share/nginx/html;
            index  index.html index.htm;

            # if ($request_uri ~* ".(jsp|sh|pl|jsp|sh|pl|jpg|jpeg|gif|gz|zip|flv|rar|wmv|avi|css|swf|png|htc|ico|mpeg|mpg|txt|mp3|mov|js)(\?v=[0-9.]+)?$") {
            #   return 404;
            #   break;
            # }

            #Proxy all the requests to Tomcat
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            # Go to next upstream after if server down.
            #proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
            #proxy_cache_methods GET HEAD POST;
            proxy_ignore_headers Expires Cache-Control;
            proxy_set_header Accept-Language 'en-US';
            add_header X-Upstream $upstream_addr always;

            add_header X-Cache-Status $upstream_cache_status always;
            add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
            #add_header X-Cache-Expiry $http_x_accel_expires;
            #Pass to tomcat backend
            proxy_pass http://tomcatcluster;
            if ($cors = true ) {
                add_header Access-Control-Allow-Origin "$http_origin"; # <- needs to be updated
                add_header Access-Control-Allow-Methods "GET, OPTIONS";
                add_header Access-Control-Allow-Headers "Authorization,User-Agent,Keep-Alive,Content-Type,x-akosha-auth";   # <- You may not need this...it's for Basic Auth
                add_header Access-Control-Allow-Credentials "true";        # <- Basic Auth stuff, again
            }
            if ($request_method = OPTIONS ) {
                add_header Access-Control-Allow-Origin "$http_origin"; # <- needs to be updated
                add_header Access-Control-Allow-Methods "GET, OPTIONS";
                add_header Access-Control-Allow-Headers "Authorization,User-Agent,Keep-Alive,Content-Type,x-akosha-auth";   # <- You may not need this...it's for Basic Auth
                add_header Access-Control-Allow-Credentials "true";        # <- Basic Auth stuff, again
                return 200;
            }

             header_filter_by_lua_block {

                ngx.header["test"] = "madhur"
                ngx.header["test1"]=ngx.resp.get_headers()['Common-Api'] 
                if ngx.resp.get_headers()['Common-Api'] == "true" then
                    ngx.var.proxy_cache_key = "$http_x_device_type$http_x_app_version_code$http_origin_api_cache_$user_agent_helpchat$host$request_uri";
                    ngx.var.ck = "$http_x_device_type$http_x_app_version_code$http_origin_api_cache_$user_agent_helpchat$host$request_uri";
                end

                if ngx.resp.get_headers()['Common-Api'] == nil then
                    ngx.var.proxy_cache_key = "$http_x_device_type$http_x_app_version_code$http_x_akosha_auth$http_x_helpchat_auth$http_origin_api_cache_$user_agent_helpchat$host$request_uri";
                    ngx.var.ck = "$http_x_device_type$http_x_app_version_code$http_x_akosha_auth$http_x_helpchat_auth$http_origin_api_cache_$user_agent_helpchat$host$request_uri";
                end

            }
            add_header X-Cache-Key $ck always;


        }
nginx lua
  • 1 个回答
  • 2611 Views
Martin Hope
IAmJulianAcosta
Asked: 2016-08-19 20:15:50 +0800 CST

使用 lua 在 nginx 中传递捕获的请求

  • 2

我正在做这样的事情:

location /foo {
        content_by_lua_block {
            local reqType = ngx.var.request_method
            if reqType == "POST"
                res = ngx.location.capture("/bar")
            else
                res = ngx.location.capture("/baz")
            end
            ngx.say(res.body)
        }
    }

    location /bar {
        internal;
        #fastcgi, omitted
    }

    location /baz{
        internal;
        #fastcgi, omitted
    }
}

但是PHP发送的标头丢失了,状态码总是200。有没有办法只发送原始响应?ngx.say()只需输出响应正文,我需要捕获整个请求并将其发送到浏览器。

我在用着openresty/1.9.15.1

编辑:我找到了一种方法来做到这一点,但如果存在任何不同的方法来做到这一点,将不胜感激。

nginx lua
  • 1 个回答
  • 1135 Views
Martin Hope
Tomcat666
Asked: 2016-08-09 05:40:57 +0800 CST

nginx 地理定位和 proxpass

  • 0

我的 Nginx 配置原型有一点问题

场景如下:网站访问者将访问 example.com。Nginx 通过 GeoIP 读取当前位置并接受来自浏览器的语言标头。

此信息必须是指proxypass

我的问题是,如何告诉 Nginx 使用带有这两个变量的 proxypass。有了这个配置,我就变成了 404 错误。

任何想法?

geoip_country   /usr/share/GeoIP/GeoIP.dat;
geoip_proxy 10.241.16.0/24; 



upstream hybrisqa {
       server qa-hybris.local:9001;
}



server {
    listen 80 default_server;
    listen [::]:80 default_server;
#   root /var/www/html;
allow all;
    access_log  /var/log/nginx/test_access.log;
    error_log  /var/log/nginx/test.error.log;



    # Add index.php to the list if you are using PHP
#   index index.html index.htm index.nginx-debian.html;

    server_name   _;

#        return 301 /$geoip_country_code;




location = / {

          rewrite_by_lua '
           if (ngx.var.http_accept_language == nil or ngx.var.http_accept_language == "") then
            ngx.redirect("/en-" .. ngx.var.geoip_country_code .. "/")
          end
          for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
          if string.sub(lang, 0, 2) == "en" then
          ngx.redirect("/en-" .. ngx.var.geoip_country_code .. "/" )
          end
          if string.sub(lang, 0, 2) == "de" then
          ngx.redirect("/de-" .. ngx.var.geoip_country_code .. "/" )
          end
          if string.sub(lang, 0, 2) == "nl" then
          ngx.redirect("/nl-" .. ngx.var.geoip_country_code .. "/"  )
          end
          end
          ngx.redirect("/en-US/")
          ';

}


location / {

 proxy_pass http://hybrisqa;


try_files $uri $uri/ =404;


}

}
nginx proxypass lua
  • 1 个回答
  • 462 Views
Martin Hope
Futh
Asked: 2016-08-06 09:39:30 +0800 CST

使用 ModSecurity 和 lua 脚本阻止请求

  • 0

我有网络流量流经 ModSecurity。

在 ModSecurity 配置中,我正在调用一个 Lua 脚本,该脚本正在对请求字符串的参数进行一些简单的分析。具体来说,它正在检查跨站点脚本的证据,如果存在一些证据,它将阻止传入的流量。

ModSecurity规则引擎配置如下:

SecRuleEngine On
SecRuleScript "/path/to/lua/script/detectXSS.lua" "block"

lua 脚本的说明性示例如下:

function main()
    -- Retrieve script parameters
    local d = m.getvars("ARGS", { "lowercase", "htmlEntityDecode" } );

    -- Loop through the parameters
    for i = 1, #d do
        -- Examine parameter value.
        if (string.find(d[i].value, "<script")) then
            return ("Suspected XSS in variable " .. d[i].name .. ".");
        end
    end

    -- Nothing wrong found.
    return nil;
end

虽然 XSS 可以被检测到并返回,但是阻塞功能并没有发生。有什么明显的缺失吗?任何帮助将不胜感激。

干杯

mod-security lua
  • 1 个回答
  • 1805 Views
Martin Hope
Mediocre Gopher
Asked: 2012-07-12 07:52:14 +0800 CST

Nginx(openresty)生成随机数

  • 4

我在服务器上设置了 openresty(包含 lua 模块的 nginx 包),我正在尝试创建一个脚本,该脚本具有在用户浏览器上设置 cookie 的特定几率。我的代码如下所示:

    location =/index.php {
        set $random_num 0;

        rewrite_by_lua '

                marth.randomseed(1);
                nvx.var.random_num = math.random(0,3);

        ';

        add_header Set-Cookie "random_num=$random_num; path=/; domain=...com;";
    }

我知道我的随机种子函数实际上并不是非常随机,但我想我稍后会处理它。目前我只是想让 nginx 设置一个随机数,但这样做会产生这个错误:

2012/07/11 11:27:20 [error] 5492#0: *44 lua handler aborted: runtime error: [string "rewrite_by_lua"]:3: attempt to ind
ex global 'marth' (a nil value)
stack traceback:

谁能告诉我我做错了什么,以及是否有任何其他方法可以在 nginx 中获取随机数?

nginx lua random-number-generator
  • 1 个回答
  • 7993 Views
Martin Hope
asdmin
Asked: 2009-08-05 01:10:13 +0800 CST

imapfilter:如何在变量中捕获部分主题

  • 0

我收到一些邮件(在 IMAP 服务器上),主题如下:

[1270503] 苹果
[1272481] 瓶子
[172481] 酒
[43172481] 葡萄

我需要在 INBOX.CSR 中移动这些字母。number其中number是主语中“ [ ] ”中的那个。如果邮箱不存在,则应创建邮箱。

由于我不熟悉 LUA 编程语言,我发现很难设置 imapfilter ( http://imapfilter.hellug.gr/ ) 来执行此操作。

update1:​​我需要重新排列 IMAP 帐户文件夹上的字母。不能进行文件操作。

linux scripting imap lua
  • 2 个回答
  • 1329 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve