V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
awanganddong
V2EX  ›  程序员

请教下 lua 怎么转发接口

  •  
  •   awanganddong · 2023-01-11 09:45:30 +08:00 · 1283 次点击
    这是一个创建于 472 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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

    6 条回复    2023-01-11 10:10:33 +08:00
    yikyo
        1
    yikyo  
       2023-01-11 09:52:34 +08:00 via iPhone
    转发不需要 lua ,nginx 本身就支持啊
    eason1874
        2
    eason1874  
       2023-01-11 09:52:38 +08:00
    代码看起来没有问题,去看看错误日志
    awanganddong
        3
    awanganddong  
    OP
       2023-01-11 09:54:17 +08:00
    @yikyo 我就直接用 nginx 了
    @eason1874 没有错误日志,这是最尴尬的点
    awanganddong
        4
    awanganddong  
    OP
       2023-01-11 09:58:15 +08:00
    刚用 nginx 转发正常,就想知道为啥 lua 转发失败。
    eason1874
        5
    eason1874  
       2023-01-11 10:01:00 +08:00
    @awanganddong 不可能没日志,除非你关掉了
    awanganddong
        6
    awanganddong  
    OP
       2023-01-11 10:10:33 +08:00
    @eason1874 我刚才测试了下,一个问题是没有加 http/https 。还有一个问题,ngx.redirect 好像是 get 跳转,并且没有携带任何参数。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   877 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.