• 请不要在回答技术问题时复制粘贴 AI 生成的内容
awanganddong
V2EX  ›  程序员

请教下 lua 怎么转发接口

  •  
  •   awanganddong · Jan 11, 2023 · 1792 views
    This topic created in 1242 days ago, the information mentioned may be changed or developed.

    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 replies    2023-01-11 10:10:33 +08:00
    yikyo
        1
    yikyo  
       Jan 11, 2023 via iPhone
    转发不需要 lua ,nginx 本身就支持啊
    eason1874
        2
    eason1874  
       Jan 11, 2023
    代码看起来没有问题,去看看错误日志
    awanganddong
        3
    awanganddong  
    OP
       Jan 11, 2023
    @yikyo 我就直接用 nginx 了
    @eason1874 没有错误日志,这是最尴尬的点
    awanganddong
        4
    awanganddong  
    OP
       Jan 11, 2023
    刚用 nginx 转发正常,就想知道为啥 lua 转发失败。
    eason1874
        5
    eason1874  
       Jan 11, 2023
    @awanganddong 不可能没日志,除非你关掉了
    awanganddong
        6
    awanganddong  
    OP
       Jan 11, 2023
    @eason1874 我刚才测试了下,一个问题是没有加 http/https 。还有一个问题,ngx.redirect 好像是 get 跳转,并且没有携带任何参数。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2729 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 12:08 · PVG 20:08 · LAX 05:08 · JFK 08:08
    ♥ Do have faith in what you're doing.