【发布时间】:2017-04-19 19:08:54
【问题描述】:
我正在运行基于 Play Framework 2.5.10 构建的 REST API 产品。它通过 NGINX 反向路由运行,我能够到达所有 GET 端点,但我在所有 POST 端点上都超时,所有这些都消耗 JSON。
请注意,在开发环境中它工作正常,我能够访问所有这些端点,但在生产环境中,无论是通过 IP 连接还是通过反向路由 DNS 连接,我都会在 POST 上超时。
高度赞赏任何解决此问题的指针。
server {
listen 80;
server_name subdomain.domain.com;
location / {
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://xxx.xxx.xxx.xxx:3000;
}
}
路由尝试访问
POST /auth controllers.Application.authenticate()
我需要在 nginx 上定义所有的路由吗?
添加授权码
@BodyParser.Of(BodyParser.Json.class)
public Result authenticate(){
JsonNode json = request().body().asJson();
EncryptUtil secure = null;
secure=EncryptUtil.getSecurityUtility();
String command = "login";
String logincommand = json.findPath("command").asText();
if (logincommand.equals(command)){
String email = json.findPath("email").textValue();
String password = json.findPath("password").textValue();
Logger.info("Passwords::"+password+"\t"+secure.getEncryptedUserPassword(password.trim()));
UserAccount user=UserAccount.findByEmail(email);
if(user!=null){
if(!(secure.getDecryptedUserPassword(user.password).equals(password))){
return status(400,"Invalid credentials");
}else {
if (user.accountstatus == Boolean.FALSE){
result.put("error","Account Deactivated Contact Admin");
return status(400,"Account Deactivated Contact Admin");
} else {
String authToken = user.createToken();
ObjectNode authTokenJson = Json.newObject();
authTokenJson.put(AUTH_TOKEN, authToken);
response().setCookie(Http.Cookie.builder(AUTH_TOKEN, authToken).withSecure(ctx().request().secure()).build());
JsonNode userJson = Json.toJson(user);
return status(200,userJson);
}
}
}
else{
result.put("Error", "Invalid User");
Logger.info(result.toString());
return status(400,"Invalid Credentials");
}
} else{
return globalFunctions.returnBadRequest(command);
}
}
【问题讨论】:
-
分享 POST 操作的方法(在你的控制器中)以及 nginx conf 的相关部分。
-
@marcospereira 我已经发布了您要求的信息。
-
您能否确认 POST 请求确实到达了您的应用程序?您能否也发布
authenticate方法的代码? -
@marcospereira 它到达但确实需要很长时间
-
“它达到但确实需要很长时间”所以,是不是响应(并且您在方法内部有与数据库的连接)慢于 300 秒?尝试测量 GET 响应的时间间隔,以及在 POST 方法中访问数据库的时间间隔。
标签: nginx playframework connection-timeout http-status-code-504