Skip to content

Commit 96910e5

Browse files
committed
Add gRPC support
1 parent 4d337d4 commit 96910e5

File tree

10 files changed

+158
-16
lines changed

10 files changed

+158
-16
lines changed

examples/customization/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ The table below summarizes all of the options. For some of them, there are examp
99
| Annotation | ConfigMaps Key | Description | Default | Example |
1010
| ---------- | -------------- | ----------- | ------- | ------- |
1111
| `kubernetes.io/ingress.class` | N/A | Specifies which Ingress controller must handle the Ingress resource. Set to `nginx` to make NGINX Ingress controller handle it. | N/A | [Multiple Ingress controllers](../multiple-ingress-controllers). |
12-
| `nginx.org/proxy-connect-timeout` | `proxy-connect-timeout` | Sets the value of the [proxy_connect_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) directive. | `60s` | |
13-
| `nginx.org/proxy-read-timeout` | `proxy-read-timeout` | Sets the value of the [proxy_read_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) directive. | `60s` | |
12+
| `nginx.org/proxy-connect-timeout` | `proxy-connect-timeout` | Sets the value of the [proxy_connect_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) and [grpc_connect_timeout](http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_connect_timeout) directive. | `60s` | |
13+
| `nginx.org/proxy-read-timeout` | `proxy-read-timeout` | Sets the value of the [proxy_read_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) and [grpc_read_timeout](http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_read_timeout) directive. | `60s` | |
1414
| `nginx.org/client-max-body-size` | `client-max-body-size` | Sets the value of the [client_max_body_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) directive. | `1m` | |
1515
| `nginx.org/proxy-buffering` | `proxy-buffering` | Enables or disables [buffering of responses](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering) from the proxied server. | `True` | |
1616
| `nginx.org/proxy-buffers` | `proxy-buffers` | Sets the value of the [proxy_buffers](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) directive. | Depends on the platform. | |
17-
| `nginx.org/proxy-buffer-size` | `proxy-buffer-size` | Sets the value of the [proxy_buffer_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) directive | Depends on the platform. | |
17+
| `nginx.org/proxy-buffer-size` | `proxy-buffer-size` | Sets the value of the [proxy_buffer_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) and [grpc_buffer_size](http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_buffer_size) directives. | Depends on the platform. | |
1818
| `nginx.org/proxy-max-temp-file-size` | `proxy-max-temp-file-size` | Sets the value of the [proxy_max_temp_file_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_max_temp_file_size) directive. | `1024m` | |
1919
| `nginx.org/proxy-hide-headers` | `proxy-hide-headers` | Sets the value of one or more [proxy_hide_header](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header) directives. Example: `"nginx.org/proxy-hide-headers": "header-a,header-b"` | N/A | |
2020
| `nginx.org/proxy-pass-headers` | `proxy-pass-headers` | Sets the value of one or more [proxy_pass_header](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_header) directives. Example: `"nginx.org/proxy-pass-headers": "header-a,header-b"` | N/A | |
@@ -51,6 +51,7 @@ The table below summarizes all of the options. For some of them, there are examp
5151
| N/A | `proxy-protocol` | Enables PROXY Protocol for incoming connections. | `False` | [Proxy Protocol](../proxy-protocol). |
5252
| `nginx.org/rewrites` | N/A | Configures URI rewriting. | N/A | [Rewrites Support](../rewrites). |
5353
| `nginx.org/ssl-services` | N/A | Enables HTTPS when connecting to the endpoints of services. | N/A | [SSL Services Support](../ssl-services). |
54+
| `nginx.org/grpc-services` | N/A | Enables gRPC for services. | N/A | [GRPC Services Support](../grpc-services).|
5455
| `nginx.org/websocket-services` | N/A | Enables WebSocket for services. | N/A | [WebSocket support](../websocket). |
5556
| `nginx.org/max-fails` | `max-fails` | Sets the value of the [max_fails](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_fails) parameter of the `server` directive. | `1` | |
5657
| `nginx.org/fail-timeout` | `fail-timeout` | Sets the value of the [fail_timeout](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#fail_timeout) parameter of the `server` directive. | `10s` | |

examples/customization/nginx-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ metadata:
44
name: nginx-config
55
namespace: nginx-ingress
66
data:
7-
proxy-connect-timeout: "10s" # default is "60s". See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout
8-
proxy-read-timeout: "10s" # default is "60s". See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout
7+
proxy-connect-timeout: "10s" # default is "60s". Sets the value of proxy_connect_timeout and grpc_connect_timeout directives. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout , http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_connect_timeout
8+
proxy-read-timeout: "10s" # default is "60s". Sets the value of proxy_read_timeout and grpc_read_timeout directives. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout , http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_read_timeout
99
proxy-hide-headers: "header-a,header-b" # No default. Sets the value of one or more proxy_hide_header directives. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header
1010
proxy-pass-headers: "header-a,header-b" # No default. Sets the value of one or more proxy_pass_header directives. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_header
1111
client-max-body-size: "2m" # default is "1m". See http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
@@ -14,7 +14,7 @@ data:
1414
http2: "True" # default is "False". Enables HTTP/2 in servers with SSL enabled. See https://nginx.org/en/docs/http/ngx_http_v2_module.html
1515
proxy-buffering: "False" # default is "True". Enables or disables buffering of responses from the proxied server. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering
1616
proxy-buffers: "16 8k" # default value depends on the platform. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
17-
proxy-buffer-size: "2k" # default value depends on the platform. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size
17+
proxy-buffer-size: "2k" # default value depends on the platform. Sets proxy_buffer_size and grpc_buffer_size. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size , http://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_buffer_size
1818
proxy-max-temp-file-size: "0" # default is "1024m". See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_max_temp_file_size
1919
log-format: '{ "@timestamp": "$time_iso8601", "@version": "1", "clientip": "$remote_addr", "tag": "ingress", "remote_user": "$remote_user", "bytes": $bytes_sent, "duration": $request_time, "status": $status, "request": "$request_uri", "urlpath": "$uri", "urlquery": "$args", "method": "$request_method", "referer": "$http_referer", "useragent": "$http_user_agent", "software": "nginx", "version": "$nginx_version", "host": "$host", "upstream": "$upstream_addr", "upstream-status": "$upstream_status" }'
2020
# log-format default is set in the nginx.conf.tmpl file. Also see http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format

examples/grpc-services/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# gRPC support
2+
3+
To add gRPC support to an application with NGINX Ingress controllers, you need to add the **nginx.org/grpc-services** annotation to your Ingress resource definition. The annotation specifies which services are gRPC services. The annotation syntax is as follows:
4+
```
5+
nginx.org/grpc-services: "service1[,service2,...]"
6+
```
7+
8+
In the following example we load balance three applications, one of which is using gRPC:
9+
```yaml
10+
apiVersion: extensions/v1beta1
11+
kind: Ingress
12+
metadata:
13+
name: grpc-ingress
14+
annotations:
15+
nginx.org/grpc-services: "grpc-svc"
16+
kubernetes.io/ingress.class: "nginx"
17+
spec:
18+
tls:
19+
- hosts:
20+
- grpc.example.com
21+
secretName: grpc-secret
22+
rules:
23+
- host: grpc.example.com
24+
http:
25+
paths:
26+
- path: /helloworld.Greeter
27+
backend:
28+
serviceName: grpc-svc
29+
servicePort: 50051
30+
- path: /tea
31+
backend:
32+
serviceName: tea-svc
33+
servicePort: 80
34+
- path: /coffee
35+
backend:
36+
serviceName: coffee-svc
37+
servicePort: 80
38+
```
39+
*grpc-svc* is a service for the gRPC application. The service becomes available at the `/helloworld.Greeter` path. Note how we used the **nginx.org/grpc-services** annotation.

nginx-controller/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM nginx:1.13.8
1+
FROM nginx:1.13.12
22

33
# forward nginx access and error logs to stdout and stderr of the ingress
44
# controller process

nginx-controller/DockerfileForAlpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM nginx:1.13.8-alpine
1+
FROM nginx:1.13.12-alpine
22

33
# forward nginx access and error logs to stdout and stderr of the ingress
44
# controller process

nginx-controller/DockerfileForPlus

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM debian:stretch-slim
22

33
LABEL maintainer="NGINX Docker Maintainers <[email protected]>"
44

5-
ENV NGINX_PLUS_VERSION 1.13.7-2~stretch
5+
ENV NGINX_PLUS_VERSION 15-2~stretch
66

77
# Download certificate and key from the customer portal (https://cs.nginx.com)
88
# and copy to the build context

nginx-controller/nginx/configurator.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
181181
spServices := getSessionPersistenceServices(ingEx)
182182
rewrites := getRewrites(ingEx)
183183
sslServices := getSSLServices(ingEx)
184+
grpcServices := getGrpcServices(ingEx)
185+
186+
// HTTP2 is required for gRPC to function
187+
if len(grpcServices) > 0 && !ingCfg.HTTP2 {
188+
glog.Errorf("Ingress %s/%s: annotation nginx.org/grpc-services requires HTTP2, ignoring", ingEx.Ingress.Namespace, ingEx.Ingress.Name)
189+
grpcServices = make(map[string]bool)
190+
}
184191

185192
if ingEx.Ingress.Spec.Backend != nil {
186193
name := getNameForUpstream(ingEx.Ingress, emptyHost, ingEx.Ingress.Spec.Backend.ServiceName)
@@ -236,6 +243,14 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
236243
var locations []Location
237244
rootLocation := false
238245

246+
grpcOnly := true
247+
for _, path := range rule.HTTP.Paths {
248+
if _, exists := grpcServices[path.Backend.ServiceName]; !exists {
249+
grpcOnly = false
250+
break
251+
}
252+
}
253+
239254
for _, path := range rule.HTTP.Paths {
240255
upsName := getNameForUpstream(ingEx.Ingress, rule.Host, path.Backend.ServiceName)
241256

@@ -244,7 +259,8 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
244259
upstreams[upsName] = upstream
245260
}
246261

247-
loc := createLocation(pathOrDefault(path.Path), upstreams[upsName], &ingCfg, wsServices[path.Backend.ServiceName], rewrites[path.Backend.ServiceName], sslServices[path.Backend.ServiceName])
262+
loc := createLocation(pathOrDefault(path.Path), upstreams[upsName], &ingCfg, wsServices[path.Backend.ServiceName], rewrites[path.Backend.ServiceName],
263+
sslServices[path.Backend.ServiceName], grpcServices[path.Backend.ServiceName])
248264
locations = append(locations, loc)
249265

250266
if loc.Path == "/" {
@@ -254,11 +270,18 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
254270

255271
if rootLocation == false && ingEx.Ingress.Spec.Backend != nil {
256272
upsName := getNameForUpstream(ingEx.Ingress, emptyHost, ingEx.Ingress.Spec.Backend.ServiceName)
257-
loc := createLocation(pathOrDefault("/"), upstreams[upsName], &ingCfg, wsServices[ingEx.Ingress.Spec.Backend.ServiceName], rewrites[ingEx.Ingress.Spec.Backend.ServiceName], sslServices[ingEx.Ingress.Spec.Backend.ServiceName])
273+
274+
loc := createLocation(pathOrDefault("/"), upstreams[upsName], &ingCfg, wsServices[ingEx.Ingress.Spec.Backend.ServiceName], rewrites[ingEx.Ingress.Spec.Backend.ServiceName],
275+
sslServices[ingEx.Ingress.Spec.Backend.ServiceName], grpcServices[ingEx.Ingress.Spec.Backend.ServiceName])
258276
locations = append(locations, loc)
277+
278+
if _, exists := grpcServices[ingEx.Ingress.Spec.Backend.ServiceName]; !exists {
279+
grpcOnly = false
280+
}
259281
}
260282

261283
server.Locations = locations
284+
server.GRPCOnly = grpcOnly
262285

263286
servers = append(servers, server)
264287
}
@@ -517,6 +540,18 @@ func getSSLServices(ingEx *IngressEx) map[string]bool {
517540
return sslServices
518541
}
519542

543+
func getGrpcServices(ingEx *IngressEx) map[string]bool {
544+
grpcServices := make(map[string]bool)
545+
546+
if services, exists := ingEx.Ingress.Annotations["nginx.org/grpc-services"]; exists {
547+
for _, svc := range strings.Split(services, ",") {
548+
grpcServices[svc] = true
549+
}
550+
}
551+
552+
return grpcServices
553+
}
554+
520555
func getSessionPersistenceServices(ingEx *IngressEx) map[string]string {
521556
spServices := make(map[string]string)
522557

@@ -595,7 +630,7 @@ func parsePort(value string) (int, error) {
595630
return int(port), nil
596631
}
597632

598-
func createLocation(path string, upstream Upstream, cfg *Config, websocket bool, rewrite string, ssl bool) Location {
633+
func createLocation(path string, upstream Upstream, cfg *Config, websocket bool, rewrite string, ssl bool, grpc bool) Location {
599634
loc := Location{
600635
Path: path,
601636
Upstream: upstream,
@@ -605,6 +640,7 @@ func createLocation(path string, upstream Upstream, cfg *Config, websocket bool,
605640
Websocket: websocket,
606641
Rewrite: rewrite,
607642
SSL: ssl,
643+
GRPC: grpc,
608644
ProxyBuffering: cfg.ProxyBuffering,
609645
ProxyBuffers: cfg.ProxyBuffers,
610646
ProxyBufferSize: cfg.ProxyBufferSize,

nginx-controller/nginx/nginx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type Server struct {
6060
SSL bool
6161
SSLCertificate string
6262
SSLCertificateKey string
63+
GRPCOnly bool
6364
StatusZone string
6465
HTTP2 bool
6566
RedirectToHTTPS bool
@@ -99,6 +100,7 @@ type Location struct {
99100
Websocket bool
100101
Rewrite string
101102
SSL bool
103+
GRPC bool
102104
ProxyBuffering bool
103105
ProxyBuffers string
104106
ProxyBufferSize string

nginx-controller/nginx/templates/nginx-plus.ingress.tmpl

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ upstream {{$upstream.Name}} {
1212

1313
{{range $server := .Servers}}
1414
server {
15+
{{if not $server.GRPCOnly}}
1516
{{range $port := $server.Ports}}
1617
listen {{$port}}{{if $server.ProxyProtocol}} proxy_protocol{{end}};
1718
{{- end}}
19+
{{end}}
1820
{{if $server.SSL}}
1921
{{- range $port := $server.SSLPorts}}
2022
listen {{$port}} ssl{{if $server.HTTP2}} http2{{end}}{{if $server.ProxyProtocol}} proxy_protocol{{end}};
@@ -33,19 +35,23 @@ server {
3335

3436
status_zone {{$server.StatusZone}};
3537

38+
{{if not $server.GRPCOnly}}
3639
{{range $proxyHideHeader := $server.ProxyHideHeaders}}
3740
proxy_hide_header {{$proxyHideHeader}};{{end}}
3841
{{range $proxyPassHeader := $server.ProxyPassHeaders}}
3942
proxy_pass_header {{$proxyPassHeader}};{{end}}
43+
{{end}}
4044

4145
{{if $server.SSL}}
46+
{{if not $server.GRPCOnly}}
4247
{{- if $server.SSLRedirect}}
4348
if ($scheme = http) {
4449
return 301 https://$host:{{index $server.SSLPorts 0}}$request_uri;
4550
}
4651
{{- end}}
4752
{{- if $server.HSTS}}
4853
add_header Strict-Transport-Security "max-age={{$server.HSTSMaxAge}}; {{if $server.HSTSIncludeSubdomains}}includeSubDomains; {{end}}preload" always;{{end}}
54+
{{end}}
4955
{{- end}}
5056
{{- if $server.RedirectToHTTPS}}
5157
if ($http_x_forwarded_proto = 'http') {
@@ -56,9 +62,9 @@ server {
5662
{{ if $server.JWTKey}}
5763
auth_jwt_key_file {{$server.JWTKey}};
5864
auth_jwt "{{$server.JWTRealm}}"{{if $server.JWTToken}} token={{$server.JWTToken}}{{end}};
59-
65+
6066
{{- if $server.JWTLoginURL}}
61-
error_page 401 @login_url;
67+
error_page 401 @login_url;
6268
location @login_url {
6369
internal;
6470
return 302 {{$server.JWTLoginURL}};
@@ -73,6 +79,32 @@ server {
7379

7480
{{range $location := $server.Locations}}
7581
location {{$location.Path}} {
82+
{{if $location.GRPC}}
83+
84+
{{- if $location.LocationSnippets}}
85+
{{range $value := $location.LocationSnippets}}
86+
{{$value}}{{end}}
87+
{{- end}}
88+
89+
grpc_connect_timeout {{$location.ProxyConnectTimeout}};
90+
grpc_read_timeout {{$location.ProxyReadTimeout}};
91+
grpc_set_header Host $host;
92+
grpc_set_header X-Real-IP $remote_addr;
93+
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
94+
grpc_set_header X-Forwarded-Host $host;
95+
grpc_set_header X-Forwarded-Port $server_port;
96+
grpc_set_header X-Forwarded-Proto $scheme;
97+
98+
{{- if $location.ProxyBufferSize}}
99+
grpc_buffer_size {{$location.ProxyBufferSize}};
100+
{{- end}}
101+
102+
{{if $location.SSL}}
103+
grpc_pass grpcs://{{$location.Upstream.Name}}
104+
{{else}}
105+
grpc_pass grpc://{{$location.Upstream.Name}};
106+
{{end}}
107+
{{else}}
76108
proxy_http_version 1.1;
77109
{{if $location.Websocket}}
78110
proxy_set_header Upgrade $http_upgrade;
@@ -110,5 +142,6 @@ server {
110142
{{else}}
111143
proxy_pass http://{{$location.Upstream.Name}}{{$location.Rewrite}};
112144
{{end}}
145+
{{end}}
113146
}{{end}}
114147
}{{end}}

nginx-controller/nginx/templates/nginx.ingress.tmpl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ upstream {{$upstream.Name}} {
99
{{range $server := .Servers}}
1010
{{if $server.IngressResource}} # *Master*, configured in Ingress Resource: {{$server.IngressResource}}{{end}}
1111
server {
12+
{{if not $server.GRPCOnly}}
1213
{{range $port := $server.Ports}}
1314
listen {{$port}}{{if $server.ProxyProtocol}} proxy_protocol{{end}};
1415
{{- end}}
16+
{{end}}
1517
{{if $server.SSL}}
1618
{{- range $port := $server.SSLPorts}}
1719
listen {{$port}} ssl{{if $server.HTTP2}} http2{{end}}{{if $server.ProxyProtocol}} proxy_protocol{{end}};
@@ -27,12 +29,13 @@ server {
2729
server_tokens {{$server.ServerTokens}};
2830

2931
server_name {{$server.Name}};
30-
32+
3133
{{range $proxyHideHeader := $server.ProxyHideHeaders}}
3234
proxy_hide_header {{$proxyHideHeader}};{{end}}
3335
{{range $proxyPassHeader := $server.ProxyPassHeaders}}
3436
proxy_pass_header {{$proxyPassHeader}};{{end}}
3537
{{if $server.SSL}}
38+
{{if not $server.GRPCOnly}}
3639
{{- if $server.SSLRedirect}}
3740
if ($scheme = http) {
3841
return 301 https://$host:{{index $server.SSLPorts 0}}$request_uri;
@@ -41,6 +44,7 @@ server {
4144
{{- if $server.HSTS}}
4245
proxy_hide_header Strict-Transport-Security;
4346
add_header Strict-Transport-Security "max-age={{$server.HSTSMaxAge}}; {{if $server.HSTSIncludeSubdomains}}includeSubDomains; {{end}}preload" always;{{end}}
47+
{{end}}
4448
{{- end}}
4549
{{- if $server.RedirectToHTTPS}}
4650
if ($http_x_forwarded_proto = 'http') {
@@ -56,6 +60,32 @@ server {
5660
{{range $location := $server.Locations}}
5761
{{if $location.IngressResource}} # *Minion*, configured in Ingress Resource: {{$location.IngressResource}}{{end}}
5862
location {{$location.Path}} {
63+
{{if $location.GRPC}}
64+
{{- if $location.LocationSnippets}}
65+
{{range $value := $location.LocationSnippets}}
66+
{{$value}}{{end}}
67+
{{- end}}
68+
69+
grpc_connect_timeout {{$location.ProxyConnectTimeout}};
70+
proxy_read_timeout {{$location.ProxyReadTimeout}};
71+
client_max_body_size {{$location.ClientMaxBodySize}};
72+
grpc_set_header Host $host;
73+
grpc_set_header X-Real-IP $remote_addr;
74+
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
75+
grpc_set_header X-Forwarded-Host $host;
76+
grpc_set_header X-Forwarded-Port $server_port;
77+
grpc_set_header X-Forwarded-Proto {{if $server.RedirectToHTTPS}}https{{else}}$scheme{{end}};
78+
79+
{{- if $location.ProxyBufferSize}}
80+
grpc_buffer_size {{$location.ProxyBufferSize}};
81+
{{- end}}
82+
83+
{{if $location.SSL}}
84+
grpc_pass grpcs://{{$location.Upstream.Name}}{{$location.Rewrite}};
85+
{{else}}
86+
grpc_pass grpc://{{$location.Upstream.Name}}{{$location.Rewrite}};
87+
{{end}}
88+
{{else}}
5989
proxy_http_version 1.1;
6090
{{if $location.Websocket}}
6191
proxy_set_header Upgrade $http_upgrade;
@@ -78,8 +108,8 @@ server {
78108
proxy_set_header X-Forwarded-Host $host;
79109
proxy_set_header X-Forwarded-Port $server_port;
80110
proxy_set_header X-Forwarded-Proto {{if $server.RedirectToHTTPS}}https{{else}}$scheme{{end}};
81-
82111
proxy_buffering {{if $location.ProxyBuffering}}on{{else}}off{{end}};
112+
83113
{{- if $location.ProxyBuffers}}
84114
proxy_buffers {{$location.ProxyBuffers}};
85115
{{- end}}
@@ -94,5 +124,6 @@ server {
94124
{{else}}
95125
proxy_pass http://{{$location.Upstream.Name}}{{$location.Rewrite}};
96126
{{end}}
127+
{{end}}
97128
}{{end}}
98129
}{{end}}

0 commit comments

Comments
 (0)