openresty nginx的请求访问windows上的tomcat报504

  1. 请求 URL:

    http://localhost/api/item/10004

  2. 请求方法:

    GET

  3. 状态代码:

    504 Gateway Time-out

  4. 远程地址:

    127.0.0.1:80

  5. 引用者策略:

    strict-origin-when-cross-origin

  6. windows的nginx.conf文件内容如下

  7. #user  nobody;

    worker_processes  1;

    events {

        worker_connections  1024;
    }

    http {

        include       mime.types;

        default_type  application/octet-stream;

        sendfile        on;

        #tcp_nopush     on;

        keepalive_timeout  65;

        upstream nginx-cluster{

            server 虚拟机IP:8081;
        }
        server {

            listen       80;

            server_name  localhost;

        location /api {

                proxy_pass http://nginx-cluster;
            }

            location / {

                root   html;

                index  index.html index.htm;
            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                root   html;
            }
        }
    }
     

  8. openresty上的nginx的nginx.conf内容如下

  9. #user  nobody;

    worker_processes  1;

    error_log  logs/error.log;

    events {

        worker_connections  1024;
    }

    http {

        include       mime.types;

        default_type  application/octet-stream;

        sendfile        on;

        keepalive_timeout  300;

        proxy_connect_timeout 100;

        proxy_read_timeout 100;

        proxy_send_timeout 100;

    #lua 模块

    lua_package_path "/usr/local/openresty/lualib/?.lua;;";

    #c模块     

    lua_package_cpath "/usr/local/openresty/lualib/?.so;;";  

        server {

            listen       8081;

            server_name  localhost;

            location / {

                root   html;

                index  index.html index.htm;
            }
        location /item{
            
            
                proxy_pass http://windowsIP:8081;

            }

    location  ~ /api/item/(\d+) {

        # 默认的响应类型

        default_type application/json;

        # 响应结果由lua/item.lua文件来决定

        content_by_lua_file lua/item.lua;

    }
            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                root   html;
            }
        }
    }
    /usr/local/openresty/lualib/common.lua内容如下


  10. local function read_http(path, params)
        local resp = ngx.location.capture(path,{
            method = ngx.HTTP_GET,
            args = params,
        })
        if not resp then
            
            ngx.log(ngx.ERR, "http QINGQIU SHIBAI, path: ", path , ", args: ", args)
            ngx.exit(404)
        end
        return resp.body
    end

    local _M = {  
        read_http = read_http
    }  
    return _M

  11. /usr/local/openresty/lua/item.lua内容如下

  12. local common = require('common')

    local read_http = common.read_http

    local id = ngx.var[1]

    local itemJSON = read_http("/item" .. id,nil)

    local stackJSON= read_http("/item/stock/" .. id,nil)

    ngx.say(itemJSON)

  13. linux虚拟机可以ping通windows主机,windows主机也可以ping通虚拟机

    哪位大神帮忙看看是哪里出了问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码的翠花

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值