Skip to content

Return 503 when service has no ready endpoints #2696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/mode/static/nginx/config/servers_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ server {
{{- end }}
{{ end }}
server {
listen unix:/var/run/nginx/nginx-502-server.sock;
listen unix:/var/run/nginx/nginx-503-server.sock;
access_log off;

return 502;
return 503;
}

server {
Expand Down
6 changes: 3 additions & 3 deletions internal/mode/static/nginx/config/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
var upstreamsTemplate = gotemplate.Must(gotemplate.New("upstreams").Parse(upstreamsTemplateText))

const (
// nginx502Server is used as a backend for services that cannot be resolved (have no IP address).
nginx502Server = "unix:/var/run/nginx/nginx-502-server.sock"
// nginx503Server is used as a backend for services that cannot be resolved (have no IP address).
nginx503Server = "unix:/var/run/nginx/nginx-503-server.sock"
// nginx500Server is used as a server for the invalid backend ref upstream.
nginx500Server = "unix:/var/run/nginx/nginx-500-server.sock"
// invalidBackendRef is used as an upstream name for invalid backend references.
Expand Down Expand Up @@ -112,7 +112,7 @@ func (g GeneratorImpl) createUpstream(up dataplane.Upstream) http.Upstream {
ZoneSize: zoneSize,
Servers: []http.UpstreamServer{
{
Address: nginx502Server,
Address: nginx503Server,
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions internal/mode/static/nginx/config/upstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestExecuteUpstreams(t *testing.T) {
"server 10.0.0.0:80;",
"server 11.0.0.0:80;",
"server [2001:db8::1]:80",
"server unix:/var/run/nginx/nginx-502-server.sock;",
"server unix:/var/run/nginx/nginx-503-server.sock;",
}

upstreamResults := gen.executeUpstreams(dataplane.Configuration{Upstreams: stateUpstreams})
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestCreateUpstreams(t *testing.T) {
ZoneSize: ossZoneSize,
Servers: []http.UpstreamServer{
{
Address: nginx502Server,
Address: nginx503Server,
},
},
},
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestCreateUpstream(t *testing.T) {
ZoneSize: ossZoneSize,
Servers: []http.UpstreamServer{
{
Address: nginx502Server,
Address: nginx503Server,
},
},
},
Expand All @@ -210,7 +210,7 @@ func TestCreateUpstream(t *testing.T) {
ZoneSize: ossZoneSize,
Servers: []http.UpstreamServer{
{
Address: nginx502Server,
Address: nginx503Server,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion site/content/how-to/monitoring/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ You can see logs for a crashed or killed container by adding the `-p` flag to th
Understanding the NGINX configuration is key for fixing issues because it shows how NGINX handles requests. This helps tweak settings to make sure NGINX behaves the way you want it to for your application. To see your current configuration, you can open a shell in the _nginx_ container by following these [steps](#get-shell-access-to-nginx-container) and run `nginx -T`. To understand the usage of NGINX directives in the configuration file, consult this list of [NGINX directives](https://nginx.org/en/docs/dirindex.html).

In this section, we will see how the configuration gets updated as we configure different Services, Deployments and HTTPRoutes with NGINX Gateway Fabric. In the configuration file, you'll often find several server blocks, each assigned to specific ports and server names. NGINX selects the appropriate server for a request and evaluates the URI against the location directives within that block.
When only a Gateway resource is defined, but no Services or HTTPRoutes are configured, NGINX generates a basic configuration. This includes a default server listening on the ports specified in the Gateway listeners, handling all incoming requests. Additionally, there are blocks to manage errors with status codes 500 or 502.
When only a Gateway resource is defined, but no Services or HTTPRoutes are configured, NGINX generates a basic configuration. This includes a default server listening on the ports specified in the Gateway listeners, handling all incoming requests. Additionally, there are blocks to manage errors with status codes 500 or 503.

This is a default `server` block listening on port 80:

Expand Down
Loading