How do I configure the NGINX Ingress Controller to increase the client request body, activate CORS to allow additional headers, and use WebSocket to work with Amazon EKS?
Last updated: 2021-12-10
I want to configure the NGINX Ingress Controller to increase the size of the client request body with my Amazon Elastic Kubernetes Service (Amazon EKS) cluster. I also want to activate Cross-Origin Resource Sharing (CORS) to allow additional headers, and use WebSocket with the NGINX Ingress Controller.
Choose one of the following configuration options:
- To increase the size of the client request body, complete the steps in the Configure maximum body size section.
- To activate CORS to allow additional headers, complete the steps in the Activate CORS section.
- To use WebSocket with the NGINX Ingress Controller, complete the steps in the Use WebSocket section.
Configure maximum body size
If your body size request exceeds the maximum allowed size of the client request body, then the NGINX Ingress Controller returns an HTTP 413 error. Use the client_max_body_size parameter to configure a larger size:
Note: The default value of the proxy-body-size is 1 M. Make sure to change the number to the size you need.
Note: In some cases, you might need to increase the maximum size for all post body data and file uploads. For PHP, you must increase the post_max_size and upload_max_file_size values in the php.ini configuration.
To activate CORS in an Ingress rule, add the following annotation:
The following example shows that header X-Forwarded-For is accepted:
You can find other headers in the Enable CORS (from the GitHub website) section of the NGINX Ingress Controller documentation.
NGINX supports WebSocket (from the NGINX website) versions 1.3 or later, without requirement. To avoid a closed connection, you must increase the proxy-read-timeout and proxy-send-timeout values.
In the following example, 120 seconds is set for proxy read timeout and proxy send timeout:
nginx.ingress.kubernetes.io/proxy-read-timeout: "120" nginx.ingress.kubernetes.io/proxy-send-timeout: "120"
Note: The default value of the preceding two annotations is 60 seconds.