-
请求 URL:
http://localhost/api/item/10004
-
请求方法:
GET
-
状态代码:
504 Gateway Time-out
-
远程地址:
127.0.0.1:80
-
引用者策略:
strict-origin-when-cross-origin
-
windows的nginx.conf文件内容如下
-
#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;
}
}
}
-
openresty上的nginx的nginx.conf内容如下
-
#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内容如下 -
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
endlocal _M = {
read_http = read_http
}
return _M -
/usr/local/openresty/lua/item.lua内容如下
-
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)
-
linux虚拟机可以ping通windows主机,windows主机也可以ping通虚拟机
哪位大神帮忙看看是哪里出了问题
openresty nginx的请求访问windows上的tomcat报504
最新推荐文章于 2024-03-10 21:35:39 发布