Nginx 播放框架端点后返回超时-504

Nginx 播放框架端点后返回超时-504,nginx,playframework,connection-timeout,http-status-code-504,Nginx,Playframework,Connection Timeout,Http Status Code 504,我正在运行一个基于Play Framework 2.5.10的REST API产品。它通过NGINX反向路由运行,我能够到达所有GET端点,但在所有POST端点上都有一个超时,所有这些都使用JSON 请注意,在开发环境中,它工作正常,我能够到达所有这些端点,但在生产环境中,无论是通过IP连接还是通过反向路由DNS连接,我在POST时都会超时 我们高度赞赏解决这一问题的任何建议 server { listen 80; server_name subdomain.domain.com; locat

我正在运行一个基于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存储临时文件的介质速度慢,这可能是由于nginx默认情况下进行的请求缓冲造成的

在日志文件中,nginx还应该警告缓存到磁盘的大型实体

如果这是您的问题,您可以使用以下指令禁用缓冲请求,该指令在
http
server
location
节中有效:

proxy_request_buffering off;
请注意,在某些情况下,如果您正在使用该功能,这将阻止故障切换到备份服务器。如果没有,你很好

另见


如果需要,您可以有选择地禁用请求缓冲,例如仅针对特定的
位置
s或仅针对
POST
方法。

共享POST操作的方法(在您的控制器中)还有nginx conf@marcospereira的相关部分。我已经发布了您请求的信息。您能否确认您的应用程序中确实收到了POST请求?您还可以发布
authenticate
method的代码吗?@marcospereira它到达但确实需要很长时间“它到达但确实需要很长时间”,那么,响应(并且您在方法中连接了数据库)是否会慢于300秒?尝试测量GET响应的时间间隔,以及POST方法中访问DB的时间间隔。