Questa pagina mostra come pubblicare un'API da un dominio personalizzato di tua proprietà, ad esempio example.com.
In alternativa all'utilizzo del tuo nome di dominio, puoi utilizzare un nome di dominio gestito da Google. Per ulteriori informazioni, consulta
Utilizzare un dominio gestito da Google.
Prima di iniziare
Se non hai ancora un nome di dominio da utilizzare per la tua API, ottienilo da un registrar di nomi di dominio.
Il modo consigliato per pubblicare un'API dalle istanze Compute Engine è
utilizzare un bilanciatore del carico in un gruppo di istanze. Devi prenotare un
indirizzo IP esterno per il nome di dominio e utilizzarlo per il bilanciatore del carico.
Per pubblicare l'API da un nome di dominio:
Prenota almeno un indirizzo IP esterno statico nel tuo progetto:
Assegna un nome qualsiasi all'indirizzo IP riservato
In Tipo, fai clic su Globale.
In Allegato a, fai clic su Nessuna. L'indirizzo IP verrà collegato a un bilanciatore del carico in un secondo momento.
Visita l'account del tuo provider di dominio e modifica le impostazioni del dominio. Devi
creare un record A che contenga il nome dell'API, ad esempio
myapi.example.com con l'indirizzo IP esterno nel relativo campo dati
Crea un gruppo di istanze che includa le istanze che eseguono l'API e
Extensible Service Proxy (ESP):
Fai clic su Definisci un servizio di backend > Crea o seleziona un servizio di backend.
Assegna il nome e la descrizione che preferisci a questa configurazione del servizio di backend.
Nel campo Protocollo, seleziona il protocollo da supportare tramite il bilanciatore del carico, HTTP o HTTPS.
Nell'elenco Gruppo di istanze, fai clic sul gruppo di istanze.
Nel campo Numeri di porta, inserisci 8080.
Fai clic su Controllo di integrità per configurare i controlli di integrità:
Inserisci un nome per la configurazione del controllo di integrità.
Assegna la porta 8080.
Per accettare i valori predefiniti rimanenti, fai clic su Salva.
Per il momento, accetta i valori predefiniti per il resto della configurazione.
Puoi apportare modifiche in un secondo momento, ad esempio aggiungere porte.
Non è necessario impostare nulla nelle Regole host e percorso. Puoi inoltrare tutto all'API di backend utilizzando i filtri predefiniti Qualsiasi senza corrispondenza. Ciò significa che tutto il traffico inviato al bilanciatore del carico viene indirizzato all'API sulla porta 8080 (la porta predefinita) come definito nei passaggi precedenti.
Fai clic su Configurazione frontend.
Nel campo Protocollo, seleziona il protocollo da supportare tramite il bilanciatore del carico, HTTP o HTTPS.
Nell'elenco IP, fai clic sull'indirizzo IP esterno che hai creato in precedenza.
Per il protocollo HTTPS, devi utilizzare SSL. Nell'elenco
Certificato, fai clic sul certificato che ti interessa.
Se vuoi supportare un altro protocollo, fai clic su
Aggiungi IP e porta frontend, specifica il protocollo, lo stesso
indirizzo IP esterno e una porta diversa.
Per creare il bilanciatore del carico completamente configurato, fai clic su Crea. Se
il pulsante Crea non è abilitato, controlla i componenti appena
configurati: accanto a ciascun componente di configurazione dovrebbe apparire un segno di spunta. Se manca il segno di spunta, significa che non hai completato la configurazione.
Dopo la propagazione delle modifiche DNS, le richieste vengono inviate all'API utilizzando il bilanciatore del carico.
GKE
Per pubblicare un'API su un dominio per Google Kubernetes Engine (GKE), devi esporre ESP come servizio utilizzando l'indirizzo IP esterno restituito per le impostazioni DNS del tuo dominio. Tieni presente che GKE
esegue automaticamente il bilanciamento del carico per te.
Per esporre l'API come servizio:
Se non ne hai già uno,
configura un servizio Kubernetes
per i backend dell'API. Crea un file di configurazione del servizio,
service.yaml, con contenuti simili ai seguenti:
Modifica l'etichetta selector in modo che corrisponda alle etichette di backend
(app: echo-app
in questo esempio)
Assicurati che targetPort corrisponda alla porta utilizzata da ESP
configurata nei backend dell'API. L'ESP utilizza la porta 8081 per impostazione predefinita.
Esegui il deployment del servizio Kubernetes:
kubectl apply -f service.yaml
Visualizza l'indirizzo IP esterno assegnato al servizio esposto:
kubectl get services
L'output mostra un indirizzo EXTERNAL-IP simile al seguente:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.X.XXX.202 10X.XXX.XX.123 8080/TCP 1m
Modifica l'indirizzo IP esterno generato da temporaneo a statico.
Seleziona il tuo indirizzo IP esterno dall'elenco.
Nell'elenco Tipo, fai clic su Statico.
Visita l'account del tuo provider di dominio e modifica le impostazioni del dominio. Devi
creare un record A che contenga il nome dell'API, ad esempio
myapi.example.com, con l'indirizzo IP esterno nel relativo campo dati.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis guide outlines the process of serving an API from a custom domain, such as \u003ccode\u003eexample.com\u003c/code\u003e, as an alternative to using a domain managed by Google.\u003c/p\u003e\n"],["\u003cp\u003eBefore configuring a custom domain, you must acquire a domain name, verify domain ownership, name your API host, obtain an SSL certificate if using SSL, and deploy your API and Extensible Service Proxy (ESP).\u003c/p\u003e\n"],["\u003cp\u003eFor App Engine, you can set your API project to use your verified domain by adding a custom domain for your application.\u003c/p\u003e\n"],["\u003cp\u003eFor Compute Engine, serving an API requires reserving a static external IP address, creating an A record with your API name, creating an instance group, and configuring an HTTP(S) load balancer.\u003c/p\u003e\n"],["\u003cp\u003eFor Google Kubernetes Engine (GKE), you must expose ESP as a service, obtain a static external IP address, and create an A record to direct traffic to your API.\u003c/p\u003e\n"]]],[],null,["# Serving an API from your domain name\n\nOpenAPI \\| [gRPC](/endpoints/docs/grpc/serving-apis-from-domains \"View this page for the Cloud Endpoints gRPC docs\")\n\n\u003cbr /\u003e\n\nThis page shows how to serve an API from a custom domain that you own, for\nexample, `example.com`.\n\nAs an alternative to using your own domain name, you can use a domain name\nmanaged by Google. See\n[Using a domain managed by Google](/endpoints/docs/openapi/configure-endpoints#using_a_domain_managed_by_google)\nfor more information.\n\nBefore you begin\n----------------\n\n- Obtain a domain name from a domain name registrar if you don't already have a domain name to use for your API.\n- [Verify domain ownership](/endpoints/docs/openapi/verify-domain-name).\n- [Name your API host name](/endpoints/docs/openapi/configure-endpoints) with your domain name.\n- If you are using SSL with your domain, obtain and upload your SSL certificate.\n- [Deploy your API and Extensible Service Proxy (ESP)](/endpoints/docs/openapi/deploy-api-backend).\n\nConfigure your API project to use your domain name\n--------------------------------------------------\n\nFollow the instructions in the appropriate tab. \n\n### App Engine\n\nTo set your API project to use your verified domain, follow the instructions\nprovided in\n[Adding a custom domain for your application](/appengine/docs/flexible/python/using-custom-domains-and-ssl)\n\n### Compute Engine\n\nThe recommended way to serve an API from Compute Engine instances is\nto use a load balancer across an instance group. You need to reserve an\nexternal IP address for the domain name and use that external IP address for\nthe load balancer.\n\nTo serve the API from a domain name:\n\n1. Reserve at least one static external IP address in your project: \n\n [Go to the External IP Addresses page](https://console.cloud.google.com/networking/addresses/add)\n 1. Assign any name you want to the reserved IP address\n 2. For **Type** , click **Global**.\n 3. For **Attached to** , click **None**. You attach the IP address to a load balancer later.\n2. Visit your domain provider account and edit your domain settings. You must create an *A record* that contains your API name, for example, `myapi.example.com` with the external IP address in its data field\n3. Create an instance group that includes the instances running your API and Extensible Service Proxy (ESP: \n\n [Go to the Create a New Instance group page](https://console.cloud.google.com/compute/instanceGroups/add)\n 1. Assign any name you want for the group and add a description.\n 2. From the **Zone** list, click the zone used by your API instance.\n 3. In the **Instance definition** list, click **Select existing instances**\n 4. In the **VM Instances** field, add the VM instance running the API.\n 5. Click **Create**.\n4. Create and configure an HTTP(S) load balancer: \n\n [Go to the Create a New HTTP(S) load balancer page](https://console.cloud.google.com/networking/loadbalancing/http/add)\n 1. Click **Define a Backend Service** \\\u003e **Create or select a backend service** . \n 2. Assign any name and description you want for this backend service configuration.\n 3. In the **Protocol** field, select the protocol you want to support through the load balancer, **HTTP** or **HTTPS**.\n 4. In the **Instance group** list, click your instance group.\n 5. In the **Port Numbers** field, enter `8080`.\n 6. Click **Health check** to configure health checks:\n - Enter a name for the health check configuration.\n - Assign the port `8080`.\n - To accept the remaining default values, click **Save**.\n 7. For now, accept the defaults for the rest of the configuration. You can make changes later as needed, such as additional ports.\n 8. You don't need to set anything in the **Host and path rules** ; you can forward everything to your backend API by using the default **Any unmatched** filters. This means that all traffic into the load balancer is directed to the API on the port `8080` (the default port) as defined in the preceding steps.\n 9. Click **Frontend configuration** . \n - In the **Protocol** field, select the protocol you want to support through the load balancer, **HTTP** or **HTTPS**.\n - In the **IP** list, click the external IP address you created earlier.\n - For the HTTPS protocol, you need to use SSL. In the **Certificate** list, click the certificate you want.\n - Optionally, if you want to support another protocol, click **Add frontend IP and port**, specify the protocol, the same external IP address, and a different port.\n 10. To create the fully configured load balancer, click **Create** . If the **Create** button isn't enabled, check the components you just configured: a checkmark should appear beside each of the configuration components. A missing checkmark means you haven't completed the configuration.\n 11. After your DNS changes propagate, requests are sent to your API by using the load balancer.\n | **Note:** If requests aren't making it through to your API backend, check your project's [firewall rules](https://console.cloud.google.com/networking/firewalls/list) to make sure your instances can accept traffic on the default ESP port `8080`. For more information, see [Firewalls](/compute/docs/networking#firewalls).\n\n### GKE\n\nTo serve an API over a domain for\nGoogle Kubernetes Engine (GKE), you need to\nexpose ESP as a service, by using the returned external IP\naddress for your domain's DNS settings. Note that GKE\nautomatically does load balancing for you.\n\nTo expose your API as a service:\n\n1. If you don't have one already, [Configure a Kubernetes service](https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/) for your API backends. Create a service configuration file, `service.yaml`, with content similar to the following: \n\n ```\n apiVersion: v1\n kind: Service\n metadata:\n name: echo\n spec:\n ports:\n - port: 80\n targetPort: 8081\n protocol: TCP\n selector:\n app: echo-app\n type: LoadBalancer\n \n ```\n - Change the `selector` label to match your backend labels (`app: echo-app` in this example)\n - Make sure the `targetPort` matches the port used by ESP configured in your API backends. ESP uses port `8081` by default.\n2. Deploy the Kubernetes service: \n\n ```\n kubectl apply -f service.yaml\n \n ```\n3. View the external IP address assigned to your exposed service: \n\n ```\n kubectl get services\n \n ```\n The output displays an `EXTERNAL-IP` address similar to the following: \n\n ```\n NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE\n hello-node 10.X.XXX.202 10X.XXX.XX.123 8080/TCP 1m\n \n ```\n | **Note:** It takes awhile for the API to be exposed as a service, and the external IP isn't visible until this process is complete. So you might have to run `kubectl get services` several times before you see the IP address.\n4. Change the generated external IP from ephemeral to static. \n\n [Go to the External IP Addresses page](https://console.cloud.google.com/networking/addresses/list)\n 1. Select your external IP address from the list.\n 2. In the **Type** list, click **Static**.\n5. Visit your domain provider account and edit your domain settings. You must create an *A record* that contains your API name, for example, `myapi.example.com`, with the external IP address in its data field.\n\nWhat's next\n-----------\n\n- [Serving multiple APIs from a domain](/endpoints/docs/openapi/deploying-apis-subdomains)"]]