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通虚拟机

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

你可能感兴趣的:(tomcat,spring,boot,linux)