1

我正在运行基于 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);
    }

}
4

1 回答 1

1

如果您的 POST 请求体很大并且连接很慢和/或 nginx 存储临时文件的介质很慢,这可能是由于 nginx 默认执行的请求缓冲造成的。

在其日志文件中,nginx 还应该警告大型机构缓存到磁盘。

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

proxy_request_buffering off;

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

另请参阅http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering

如果需要,您可以有选择地禁用请求缓冲,例如仅针对某些locations 或仅针对该POST方法。

于 2017-04-29T09:25:53.940 回答