Jika Anda ingin menggunakan nginx.conf kustom di Google Kubernetes Engine, siapkan nginx.conf tersebut dengan
memperluas
sample nginx.conf ini.
Berikut adalah cuplikan konfigurasi yang diperlukan oleh Cloud Endpoints:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[[["\u003cp\u003eUsing the \u003ccode\u003e-n\u003c/code\u003e flag to provide a custom nginx configuration is generally not recommended, as it can lead to feature breakage; instead, the preferred method is to modify a copy of the automatically generated configuration.\u003c/p\u003e\n"],["\u003cp\u003eTo customize the nginx configuration, deploy an ESP container, copy the generated \u003ccode\u003enginx.conf\u003c/code\u003e from \u003ccode\u003e/etc/nginx/endpoints/\u003c/code\u003e, and make your changes to the copied file.\u003c/p\u003e\n"],["\u003cp\u003eWhen using a custom \u003ccode\u003enginx.conf\u003c/code\u003e on Google Kubernetes Engine, you should use the provided sample configuration as a base and ensure that it contains the required settings for Cloud Endpoints.\u003c/p\u003e\n"],["\u003cp\u003eThe nginx configuration must include specific directives like \u003ccode\u003eendpoints { on; }\u003c/code\u003e and after ESP version 1.7.0, the \u003ccode\u003eserver_config\u003c/code\u003e field should be set to \u003ccode\u003e/etc/nginx/server_config.pb.txt\u003c/code\u003e for proper functionality.\u003c/p\u003e\n"],["\u003cp\u003eAfter creating a custom \u003ccode\u003enginx.conf\u003c/code\u003e, it needs to be deployed into Kubernetes via a ConfigMap and referenced within the Kubernetes configuration file, ensuring that the ESP container's arguments point to the custom configuration location.\u003c/p\u003e\n"]]],[],null,["# Using a custom nginx.conf on GKE\n\nOpenAPI \\| [gRPC](/endpoints/docs/grpc/custom-nginx \"View this page for the Cloud Endpoints gRPC docs\")\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"]]