Se você quiser usar um nginx.conf personalizado no Google Kubernetes Engine, prepare um estendendo esta amostra nginx.conf. Aqui está um snippet de configuração exigido pelo Cloud Endpoints:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[[["\u003cp\u003eUsing a custom nginx configuration with the \u003ccode\u003e-n\u003c/code\u003e flag is generally not recommended as it can disrupt the intended functionality of ESP.\u003c/p\u003e\n"],["\u003cp\u003eThe preferred method to customize the nginx configuration involves deploying an ESP container, copying the generated config, and modifying the copy, repeating this process for new ESP versions or flag changes.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize a custom \u003ccode\u003enginx.conf\u003c/code\u003e on Google Kubernetes Engine, one should extend the provided sample configuration and include specific Cloud Endpoints configurations in it, such as including \u003ccode\u003e/etc/nginx/mime.types\u003c/code\u003e and utilizing the endpoints feature with relevant fields.\u003c/p\u003e\n"],["\u003cp\u003eAfter creating a custom \u003ccode\u003enginx.conf\u003c/code\u003e, you can deploy it to Kubernetes by creating a ConfigMap and then updating your Kubernetes configuration to reference the custom nginx configuration.\u003c/p\u003e\n"]]],[],null,["# Using a custom nginx.conf on GKE\n\n[OpenAPI](/endpoints/docs/openapi/custom-nginx \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\n\n\u003cbr /\u003e\n\n| **Warning** : Using this flag is not recommended as it may break many features. Normally, ESP uses the nginx config generated from its start up flags. If a custom nginx config is provided with flag \\`-n\\`, the generated nginx config is not be used and ESP will not function properly.\n|\n| The preferred method for generating a custom nginx config is:\n|\n| - Deploy an ESP container with the proper start up flags\n| - Copy the generated nginx config from `/etc/nginx/endpoints/nginx.conf`\n| - Apply your changes to the copy of the generated nginx.config\n|\n| The steps above must be repeated whenever a new ESP version is used or any start up flags are changed.\n\nIf you want to use a custom `nginx.conf` on Google Kubernetes Engine, prepare one by\nextending this\n[sample nginx.conf](https://github.com/GoogleCloudPlatform/endpoints-samples/blob/master/k8s/nginx.conf).\nHere is a snippet of the configuration required by Cloud Endpoints: \n\n http {\n include /etc/nginx/mime.types;\n server_tokens off;\n client_max_body_size 32m;\n\n upstream app_server {\n server localhost:8081;\n keepalive 128;\n }\n\n endpoints {\n metadata_server;\n }\n\n server {\n # Running port\n listen 8080;\n\n # Running ssl port\n listen 443 ssl;\n ssl_certificate /etc/nginx/ssl/nginx.crt;\n ssl_certificate_key /etc/nginx/ssl/nginx.key;\n\n # Logging to stdout enables better integration with Docker and GKE/Kubernetes.\n access_log /dev/stdout;\n\n location / {\n # Begin Endpoints v2 Support\n endpoints {\n on;\n # After ESP 1.7.0, \"server_config\" field is required.\n # It has to be /etc/nginx/server_config.pb.txt exactly.\n # If not present, some new features will not work.\n server_config /etc/nginx/server_config.pb.txt;\n\n # After ESP 1.7.0, \"api\" field is not required.\n # If added, it has to be /etc/nginx/endpoints/service.json exactly.\n # api /etc/nginx/endpoints/service.json;\n\n # Uncomment the line below if you are not using Google Container Engine.\n # The path should be set to the \"-k\" path specified in the ESP container's \n # args section in the Kubernetes yaml config.\n # google_authentication_secret /etc/nginx/creds/service-account-creds.json;\n }\n # End Endpoints v2 Support\n\n proxy_pass http://app_server;\n proxy_redirect off;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Host $server_name;\n proxy_set_header X-Google-Real-IP $remote_addr;\n\n # 86400 seconds (24 hours) is the maximum a server is allowed.\n proxy_send_timeout 86400s;\n proxy_read_timeout 86400s;\n }\n\n include /var/lib/nginx/extra/*.conf;\n }\n\n server {\n # expose /nginx_status but on a different port to avoid\n # external visibility / conflicts with the app.\n listen 8090;\n location /nginx_status {\n stub_status on;\n access_log off;\n }\n location / {\n root /dev/null;\n }\n }\n }\n\nNow create a Kubernetes Configmap with your custom `nginx.conf` using `kubectl`: \n\n```bash\nkubectl create configmap nginx-config --from-file=nginx.conf\n```\n\nEdit the Kubernetes configuration file such as\n[`esp_echo_custom_config_gke.yaml`](https://github.com/GoogleCloudPlatform/endpoints-samples/blob/master/k8s/esp_echo_custom_config_gke.yaml)\nand replace `SERVICE_NAME` with the name of your Endpoints service. \n\n template:\n metadata:\n labels:\n app: esp-echo\n spec:\n volumes:\n - name: nginx-config\n configMap:\n name: nginx-config\n - name: nginx-ssl\n secret:\n secretName: nginx-ssl\n containers:\n - name: esp\n image: gcr.io/endpoints-release/endpoints-runtime:1\n args: [\n \"-n\", \"/etc/nginx/custom/nginx.conf\",\n \"-s\", \"SERVICE_NAME\",\n \"--rollout_strategy\", \"managed\",\n ]\n ports:\n - containerPort: 8080\n - containerPort: 443\n volumeMounts:\n - mountPath: /etc/nginx/ssl\n name: nginx-ssl\n readOnly: true\n - mountPath: /etc/nginx/custom\n name: nginx-config\n readOnly: true\n - name: echo \n image: gcr.io/endpoints-release/echo:latest\n ports:\n - containerPort: 8081\n\nFinally, start the service with the updated Kubernetes configuration file using\n`kubectl`. \n\n kubectl create -f esp_echo_custom_config_gke.yaml"]]