错误 HTTP 状态 405?使用 GCP 负载平衡器时不允许的方法
ERROR HTTP Status 405 ? Method Not Allowed when using GCP load balancer
我在 spring 启动时创建了一个应用程序,它从远程 PostgreSQL 数据库恢复数据。它在本地运行良好(从本地应用程序到本地数据库),从本地主机到远程数据库以及 GCP 云上的所有资源(vm with tomcat 托管应用程序的服务器和云 SQL for Postgre SQL 数据库)。我的 PoC 的最后一部分是在我的实例组中托管我的应用程序,并附加一个负载均衡器。当我到达我的负载平衡器时,我可以看到我的欢迎页面,我在其中使用 spring 安全性登录(从同一个 postgreSQL 数据库中恢复凭据),但它不起作用,我收到下一个错误:
LB error page
当我检查 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 terraform 代码,'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
}
}
在此感谢您的帮助。
我通过负载均衡器本身生成的 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
}
}
我在 spring 启动时创建了一个应用程序,它从远程 PostgreSQL 数据库恢复数据。它在本地运行良好(从本地应用程序到本地数据库),从本地主机到远程数据库以及 GCP 云上的所有资源(vm with tomcat 托管应用程序的服务器和云 SQL for Postgre SQL 数据库)。我的 PoC 的最后一部分是在我的实例组中托管我的应用程序,并附加一个负载均衡器。当我到达我的负载平衡器时,我可以看到我的欢迎页面,我在其中使用 spring 安全性登录(从同一个 postgreSQL 数据库中恢复凭据),但它不起作用,我收到下一个错误:
LB error page
当我检查 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 terraform 代码,'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
}
}
在此感谢您的帮助。
我通过负载均衡器本身生成的 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
}
}