错误http状态405?使用gcp负载平衡器时不允许使用方法

hmae6n7t  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(427)

我在SpringBoot中有一个应用程序,它从远程postgresql数据库恢复数据。它在本地(从本地应用程序到本地数据库)、从本地主机到远程数据库以及gcp云上的所有资源(虚拟机与托管应用程序的tomcat服务器以及用于postgresql数据库的云sql)运行良好。poc的最后一部分是在示例组中承载应用程序,并连接负载平衡器。当我到达负载均衡器时,我可以看到我的欢迎页面,在那里我使用spring security登录(重新转换来自同一postgresql数据库的凭据),但它不工作,我收到下一个错误:
lb错误页
当我检查catalina.out日志时,它会显示下一个错误:

11:34 ERROR 893 --- [io-8080-exec-11] o.s.b.w.servlet.support.ErrorPageFilter  : Cannot forward to error page for request [/login] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
11:35  WARN 893 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

如果有帮助的话,我将分享我的lb地形代码,`lb部分似乎是我poc中的问题。

provider "google-beta" {
  project     = var.project
  region      = "us-central1"
  credentials = "C:/Users/jperezgarcia/Desktop/Terraform/GCP/credentials/mario.json"
}

resource "google_compute_region_ssl_certificate" "ssl-crt" {
  provider    = google-beta
  project     = var.project
  name_prefix = "my-certificate-"
  region      = var.lb_region
  private_key = file("lb_http/certificate/privateKey.key")
  certificate = file("lb_http/certificate/certificate.crt")

  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_forwarding_rule" "lb-front-HTTP" {
  provider              = google-beta
  project               = var.project
  name                  = var.lb_front_name
  load_balancing_scheme = "INTERNAL_MANAGED"
  port_range            = var.lb_front_port_range
  target                = google_compute_region_target_http_proxy.lb-proxy-http.self_link
  region                = var.lb_region
  network               = var.lb_network
  subnetwork            = var.lb_subnetwork
  # ip_address            = "10.10.20.5"
}

resource "google_compute_forwarding_rule" "lb-front-HTTPS" {
  provider              = google-beta
  project               = var.project
  name                  = "lb-https-front"
  port_range            = "443"
  load_balancing_scheme = "INTERNAL_MANAGED"
  # ip_address            = "10.10.20.5"
  target     = google_compute_region_target_https_proxy.lb-proxy-https.self_link
  region     = var.lb_region
  network    = var.lb_network
  subnetwork = var.lb_subnetwork
}

resource "google_compute_region_target_http_proxy" "lb-proxy-http" {
  provider = google-beta
  name     = var.lb_proxy_name
  region   = var.lb_region
  project  = var.project
  url_map  = google_compute_region_url_map.lb_url_map.self_link
}

resource "google_compute_region_target_https_proxy" "lb-proxy-https" {
  provider         = google-beta
  name             = "test-proxy"
  region           = var.lb_region
  project          = var.project
  url_map          = google_compute_region_url_map.lb_url_map.self_link
  ssl_certificates = [google_compute_region_ssl_certificate.ssl-crt.id]
}

resource "google_compute_region_url_map" "lb_url_map" {
  provider        = google-beta
  project         = var.project
  name            = var.url_map_name
  region          = var.lb_region
  default_service = google_compute_region_backend_service.lb-backend.self_link
}

resource "google_compute_region_backend_service" "lb-backend" {
  provider              = google-beta
  name                  = var.lb_backend_name
  region                = var.lb_region
  project               = var.project
  load_balancing_scheme = "INTERNAL_MANAGED"
  port_name             = var.lb_backend_port_name
  protocol              = var.lb_backend_protocol
  timeout_sec           = var.lb_backend_timeout
  health_checks         = [var.healthcheck_output]
  locality_lb_policy    = "ROUND_ROBIN"
  session_affinity      = "GENERATED_COOKIE"
  affinity_cookie_ttl_sec= 3600
  log_config {
    enable = true
  }

  backend {
    group           = var.ig_id
    balancing_mode  = "UTILIZATION"
    capacity_scaler = 1.0
  }
}

谢谢你的帮助。

ccgok5k5

ccgok5k51#

我通过负载平衡器本身生成的cookie解决了这个问题。我尝试使用循环lb,但如果您必须保持会话处于打开状态,则没有任何意义,您必须使用环哈希。我将分享脚本(查看后端服务):

provider "google-beta" {
  project     = var.project
  region      = var.region
  credentials = var.credentials
}

resource "google_compute_region_ssl_certificate" "ssl-crt" {
  provider    = google-beta
  project     = var.project
  name_prefix = var.certificate_name
  region      = var.lb_region
  private_key = file("lb_http/certificate/privateKey.key")
  certificate = file("lb_http/certificate/certificate.crt")

  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_forwarding_rule" "lb-front-HTTP" {
  provider              = google-beta
  project               = var.project
  name                  = var.lb_http_front_name
  load_balancing_scheme = "INTERNAL_MANAGED"
  port_range            = var.lb_front_port_range
  target                = google_compute_region_target_http_proxy.lb-proxy-http.self_link
  region                = var.lb_region
  network               = var.lb_network
  subnetwork            = var.lb_subnetwork
  # ip_address            = "10.10.20.5"
}

resource "google_compute_forwarding_rule" "lb-front-HTTPS" {
  provider              = google-beta
  project               = var.project
  name                  = "lb-https-front"
  port_range            = "443"
  load_balancing_scheme = "INTERNAL_MANAGED"
  # ip_address            = "10.10.20.5"
  target     = google_compute_region_target_https_proxy.lb-proxy-https.self_link
  region     = var.lb_region
  network    = var.lb_network
  subnetwork = var.lb_subnetwork
}

resource "google_compute_region_target_http_proxy" "lb-proxy-http" {
  provider = google-beta
  name     = var.lb_proxy_name
  region   = var.lb_region
  project  = var.project
  url_map  = google_compute_region_url_map.lb_url_map.self_link
}

resource "google_compute_region_target_https_proxy" "lb-proxy-https" {
  provider         = google-beta
  name             = "test-proxy"
  region           = var.lb_region
  project          = var.project
  url_map          = google_compute_region_url_map.lb_url_map.self_link
  ssl_certificates = [google_compute_region_ssl_certificate.ssl-crt.id]
}

resource "google_compute_region_url_map" "lb_url_map" {
  provider        = google-beta
  project         = var.project
  name            = var.url_map_name
  region          = var.lb_region
  default_service = google_compute_region_backend_service.lb-backend.self_link
}

resource "google_compute_region_backend_service" "lb-backend" {
  provider                        = google-beta
  name                            = var.lb_backend_name
  region                          = var.lb_region
  project                         = var.project
  load_balancing_scheme           = "INTERNAL_MANAGED"
  port_name                       = var.lb_backend_port_name
  protocol                        = var.lb_backend_protocol
  timeout_sec                     = var.lb_backend_timeout
  health_checks                   = [var.healthcheck_output]
  locality_lb_policy              = "RING_HASH"
  session_affinity                = "GENERATED_COOKIE"
  affinity_cookie_ttl_sec         = 3600
  connection_draining_timeout_sec = 300
  log_config {
    enable = true
  }

  consistent_hash {
    minimum_ring_size = 3
    http_cookie {
      ttl {
        seconds = 11
        nanos   = 1111
      }
      name = "mycookie"
    }
  }

  backend {
    group           = var.ig_id
    balancing_mode  = "UTILIZATION"
    capacity_scaler = 1.0
  }
}

相关问题