请教下 lua 怎么转发接口

2023-01-11 09:45:30 +08:00
 awanganddong

nginx 配置如下

这个是 nginx 配置文件

   location ~ \.php$ {
        access_by_lua_file /etc/nginx/conf.d/lua/bitian.lua;

        fastcgi_pass  unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
   }
lua 文件如下

local uri = ngx.var.request_uri
if uri == "/test" then
    return ngx.redirect("www.test.com")
end

访问 /test 接口直接 502

1296 次点击
所在节点    程序员
6 条回复
yikyo
2023-01-11 09:52:34 +08:00
转发不需要 lua ,nginx 本身就支持啊
eason1874
2023-01-11 09:52:38 +08:00
代码看起来没有问题,去看看错误日志
awanganddong
2023-01-11 09:54:17 +08:00
@yikyo 我就直接用 nginx 了
@eason1874 没有错误日志,这是最尴尬的点
awanganddong
2023-01-11 09:58:15 +08:00
刚用 nginx 转发正常,就想知道为啥 lua 转发失败。
eason1874
2023-01-11 10:01:00 +08:00
@awanganddong 不可能没日志,除非你关掉了
awanganddong
2023-01-11 10:10:33 +08:00
@eason1874 我刚才测试了下,一个问题是没有加 http/https 。还有一个问题,ngx.redirect 好像是 get 跳转,并且没有携带任何参数。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/908072

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX