问题描述
我有一个蒸气Web应用程序在Nginx之后反向代理。该应用程序需要进行外部API调用。该API调用可以在本地托管(没有Nginx)下进行良好的测试,但是在Nginx后面的VPS上发出请求时,出现了502错误。
upstream prematurely closed connection while reading response header from upstream,client: XX.XXX.XXX.XX,server: myserver.com,request: "GET /auth/substat/XXXXX HTTP/1.1",upstream: "http://127.0.0.1:8080/auth/substat/XXXXX",host: "myserver.com"
Nginx相关配置:
server {
server_name myserver.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myserver.com;/fullchain.pem; # manage$
ssl_certificate_key /etc/letsencrypt/live/myserver.com;/privkey.pem; # mana$
include /etc/letsencrypt/options-ssl-Nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
vapor API代码:
func subscriptionStatus(_ req: Request) throws -> EventLoopFuture<StatusResponse> {
var response : StatusResponse = StatusResponse(response: .failure,subscribed: .no)
let id = req.parameters.get("id")!
let key = Environment.get("REV_CAT_SECRET")!
let query = "https://api.revenuecat.com/v1/subscribers/\(id)"
let headers = HTTPHeaders([("authorization","Bearer \(key)"),("Content-Type","application/json"),("x-platform","stripe")])
return try req.client.get(URI(string:query),headers: headers).map { res in
if let obj = try? res.content.decode(RevCatResponse.self) {
let annual = obj.subscriber.subscriptions.myannualproduct?.expiresDate
let monthly = obj.subscriber.subscriptions.mymonthlyproduct?.expiresDate
if annual != nil && annual! > Date() {
response = StatusResponse(response: .success,subscribed: .yes)
} else if monthly != nil && monthly! > Date() {
response = StatusResponse(response: .success,subscribed: .yes)
} else {
response = StatusResponse(response: .success,subscribed: .no)
}
} else {
response = StatusResponse(response: .failure,subscribed: .no)
}
}.map {
return response
}
}
我想念什么?预先感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)