Recently, there are two problems that need to be solved when using k8s clusters for business. Here are some records:

  • 1M limit for uploading files on the front-end page
  • 504 timeout occurs when the front-end page sends a POST request to the back-end

The main solution to the first problem: the default upload size of nginx is 1M, and the following content is added to the http, server, location area of the nginx configuration file:

1
client_max_body_size 800M;

The main solution to the second problem: the default timeout for reading the back-end in nginx is 1 minute, and the following content is added to the http, server, location area of the nginx configuration file:

1
2
3
proxy_connect_timeout 120;
proxy_read_timeout 900;
proxy_send_timeout 900;

Finally, the nginx configuration is as follows:

1
2
3
4
5
6
7
8
9
server {
listen 80;
server_name web_server;
location / {
root /usr/share/nginx/html/;
index index.htm index.html; try_files $uri $uri/ /index.html; } location /business-operation { proxy_pass http://business-operat.common:5000; proxy_ignore_client_abort on; keepalive_timeout 900s; client_body_timeout 900s; proxy_connect_timeout 120s; proxy_read_timeout 900s; proxy_send_timeout 900s; client_max_body; _size 800m; proxy_pass_header Authorization; proxy_pass_header WWW-Authenticate; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}

Finally, after adjusting the above nginx configuration, you also need to include this information in the annotation when creating ingress:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "800M"
nginx.ingress.kubernetes.io/proxy-connect-timeout: '120'
nginx.ingress.kubernetes.io/proxy-read-timeout: '900'
nginx.ingress.kubernetes.io/proxy-send-timeout: '900'
name: enterprise-mark
namespace: frontend
spec:
rules:
- host: enterprise-marketing.xxxx.com http: paths: - backend: serviceName: enterprise-mark servicePort: 80 path: / status: loadBalancer: ingress: - ip: 39.107.xxx.xxx ````