Comme décrit dans la section Ajouter la compatibilité CORS à ESP, vous pouvez configurer Extensible Service Proxy (ESP) afin d'assurer la compatibilité avec CORS.
Si les options ESP ne permettent pas la compatibilité avec le mécanisme CORS requise par votre application, vous pouvez ajouter les options CORS au fichier de configuration ESP nginx.conf.
Ajouter les options CORS à nginx.conf
Pour ajouter les options CORS, procédez comme suit :
Commencez avec un fichier nginx.conf contenant la configuration requise par Cloud Endpoints. Vous pouvez commencer avec l'exemple nginx.conf ou, si vous avez déjà déployé ESP, vous pouvez vous connecter en SSH au conteneur ESP et copier le fichier nginx.conf à partir du répertoire /etc/nginx/endpoints/.
Ajoutez les options CORS requises par votre application au fichier nginx.conf. Vous pouvez utiliser l'exemple CORS on NGINX (CORS sur NGINX) comme point de départ.
Démarrez ESP en spécifiant l'option --nginx_config avec le chemin d'accès au fichier personnalisé nginx.conf.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThe Extensible Service Proxy (ESP) can be configured to support CORS, as described in the documentation about adding CORS support to ESP.\u003c/p\u003e\n"],["\u003cp\u003eIf ESP's default options are insufficient, you can customize CORS support by editing the \u003ccode\u003enginx.conf\u003c/code\u003e configuration file.\u003c/p\u003e\n"],["\u003cp\u003eA sample \u003ccode\u003enginx.conf\u003c/code\u003e file, or an existing one from a deployed ESP container, can serve as the basis for customization.\u003c/p\u003e\n"],["\u003cp\u003eAfter adding your required CORS options to \u003ccode\u003enginx.conf\u003c/code\u003e, ESP must be started with the \u003ccode\u003e--nginx_config\u003c/code\u003e option pointing to this modified file.\u003c/p\u003e\n"]]],[],null,["# Creating a Custom nginx.conf to Support CORS\n\n[OpenAPI](/endpoints/docs/openapi/custom-cors-nginx \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\n\n\u003cbr /\u003e\n\nAs described in [Adding CORS support to\nESP](/endpoints/docs/grpc/specify-proxy-startup-options#adding_cors_support_to_esp),\nyou can configure the [Extensible Service Proxy\n(ESP)](/endpoints/docs/grpc/glossary#extensible_service_proxy) to support CORS.\nIf the ESP options don't provide the CORS support that your\napplication requires, you can add the CORS options to ESP's configuration file,\n`nginx.conf`.\n\nAdding the CORS options to `nginx.conf`\n---------------------------------------\n\nTo add the CORS options:\n\n1. Start with a `nginx.conf` file that contains the configuration required by\n Cloud Endpoints. You can start with the [sample\n `nginx.conf`](https://github.com/GoogleCloudPlatform/endpoints-samples/blob/master/k8s/nginx.conf),\n or if you have already deployed ESP, you can SSH to the ESP container and\n copy the `nginx.conf` file from the `/etc/nginx/endpoints/` directory.\n\n2. Add the CORS options that your application requires to `nginx.conf`. You can\n use the [CORS on NGINX](https://enable-cors.org/server_nginx.html) example\n as a starting point.\n\n3. Start ESP with the `--nginx_config` option with the path to the custom\n `nginx.conf` file.\n\nWhat's next\n-----------\n\n- Learn about [ESP's startup options](/endpoints/docs/grpc/specify-proxy-startup-options).\n\n- Learn how to [SSH to ESP's container on GKE](/endpoints/docs/grpc/troubleshoot-gke-deployment#checking_configuration_files).\n\n- Learn about [using a custom nginx.conf on GKE](/endpoints/docs/grpc/custom-nginx)."]]