Auf dieser Seite wird gezeigt, wie eine API von einer benutzerdefinierten Domain geliefert wird, die Ihnen gehört, z. B. example.com.
Anstelle des eigenen Domainnamens können Sie auch einen von Google verwalteten Domainnamen verwenden. Weitere Informationen finden Sie unter Von Google verwaltete Domain verwenden.
Vorbereitung
Fordern Sie bei einem Domainnamenregistrator einen Domainnamen an, wenn Sie noch keinen Domainnamen haben, der für Ihre API genutzt werden kann.
API-Projekt für die Verwendung meines Domainnamens konfigurieren
Folgen Sie der Anleitung auf dem entsprechenden Tab.
Compute Engine
Zum Bereitstellen einer API aus Compute Engine-Instanzen wird die Verwendung eines Load-Balancer in einer Instanzgruppe empfohlen. Sie müssen eine externe IP-Adresse für den Domainnamen reservieren und diese externe IP-Adresse für den Load-Balancer verwenden.
API über einen Domainnamen bereitstellen:
Reservieren Sie in Ihrem Projekt mindestens eine statische externe IP-Adresse:
Weisen Sie der reservierten IP-Adresse einen beliebigen Namen zu.
Klicken Sie unter Type (Typ) auf Global.
Klicken Sie unter Attached to (Zugeordnet zu) auf None (Keine). Sie fügen die IP-Adresse später zu einem Load-Balancer hinzu.
Bearbeiten Sie Ihre Domaineinstellungen in Ihrem Domainanbieterkonto. Sie müssen einen A-Datensatz erstellen, der Ihren API-Namen enthält, z. B. myapi.example.com mit der externen IP-Adresse im Datenfeld
Erstellen Sie eine Instanzgruppe mit den Instanzen, die Ihre API und den Extensible Service Proxy (ESP) ausführen:
Klicken Sie auf Back-End-Dienst definieren > Back-End-Dienst erstellen oder auswählen.
Geben Sie einen beliebigen Namen und eine Beschreibung für diese Back-End-Dienstkonfiguration an.
Wählen Sie im Feld Protokoll das Protokoll aus, das Sie über den Load-Balancer HTTP oder HTTPS unterstützen möchten.
Klicken Sie in der Liste Instance group (Instanzgruppe) auf die Instanzgruppe.
Geben Sie im Feld Port Numbers (Portnummern) den Wert 8080 ein.
Klicken Sie auf Systemdiagnose, um Systemdiagnosen zu konfigurieren:
Geben Sie eine Bezeichnung für die Konfiguration der Systemdiagnose ein.
Weisen Sie den Port 8080 zu.
Klicken Sie zum Übernehmen der verbleibenden Standardwerte auf Save (Speichern).
Akzeptieren Sie für die restliche Konfiguration vorerst die Standardeinstellungen.
Sie können Änderungen später bei Bedarf vornehmen und beispielsweise zusätzliche Ports hinzufügen.
Im Feld Host and path rules (Host- und Pfadregeln) müssen Sie keinen Wert eingeben. Sie können alles an Ihre Back-End API weiterleiten, indem Sie die Standardfilter Any unmatched (Alle nicht zugeordneten Pfade) verwenden. Auf diese Weise wird der gesamte im Load-Balancer eingehende Traffic über den Standardport 8080 an die API weitergeleitet (siehe oben).
Klicken Sie auf Frontend-Konfiguration.
Wählen Sie im Feld Protokoll das Protokoll aus, das Sie über den Load-Balancer HTTP oder HTTPS unterstützen möchten.
Klicken Sie in der Liste IP auf die zuvor erstellte externe IP-Adresse.
Für das HTTPS-Protokoll müssen Sie SSL verwenden. Klicken Sie in der Liste Certificate (Zertifikat) auf das gewünschte Zertifikat.
Wenn Sie ein anderes Protokoll unterstützen möchten, klicken Sie optional auf Add frontend IP and port (Frontend-IP und Port hinzufügen) und geben Sie das Protokoll, die gleiche externe IP-Adresse und einen anderen Port an.
Zum Erstellen des vollständig konfigurierten Load-Balancers klicken Sie auf Create (Erstellen). Wenn die Schaltfläche Create (Erstellen) deaktiviert ist, prüfen Sie die zuvor konfigurierten Komponenten: Neben jeder Konfigurationskomponente sollte ein Häkchen angezeigt werden. Ein fehlendes Häkchen weist darauf hin, dass die Konfiguration nicht abgeschlossen ist.
Sobald die DNS-Änderungen verteilt wurden, werden Anfragen über den Load-Balancer an die API gesendet.
GKE
Zum Bereitstellen einer API über eine Domain für Google Kubernetes Engine (GKE) müssen Sie den ESP als Dienst freigeben. Verwenden Sie dazu die zurückgegebene externe IP-Adresse für die DNS-Einstellungen Ihrer Domain. Beachten Sie, dass GKE automatisch Load-Balancing ausführt.
API als Dienst bereitstellen:
Konfigurieren Sie einen Kubernetes-Dienst für Ihre API-Back-Ends, sofern noch nicht geschehen. Erstellen Sie die Dienstkonfigurationsdatei service.yaml mit folgendem Inhalt:
Ändern Sie das Label selector entsprechend Ihren Back-End-Labels (in diesem Beispiel app: echo-app).
Prüfen Sie, ob der targetPort mit dem vom ESP verwendeten Port übereinstimmt, der in den API-Back-Ends konfiguriert ist. Der ESP verwendet standardmäßig Port 8081.
Stellen Sie den Kubernetes-Dienst bereit:
kubectl apply -f service.yaml
Rufen Sie die externe IP-Adresse auf, die dem freigegebenen Dienst zugewiesen ist:
kubectl get services
Die Ausgabe zeigt eine EXTERNAL-IP-Adresse an, die in etwa so aussieht:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.X.XXX.202 10X.XXX.XX.123 8080/TCP 1m
Ändern Sie die generierte externe IP-Adresse von sitzungsspezifisch in statisch.
Wählen Sie die externe IP-Adresse aus der Liste aus.
Klicken Sie in der Liste Type (Typ) auf Static (Statisch).
Bearbeiten Sie Ihre Domaineinstellungen in Ihrem Domainanbieterkonto. Sie müssen einen A-Datensatz erstellen, der Ihren API-Namen enthält, z. B. myapi.example.com, wobei die externe IP-Adresse im Datenfeld enthalten ist.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[[["\u003cp\u003eThis page guides users on serving an API from a custom domain they own, such as \u003ccode\u003eexample.com\u003c/code\u003e, as an alternative to using a Google-managed domain.\u003c/p\u003e\n"],["\u003cp\u003eBefore beginning, users must obtain a domain name, verify ownership, name their API host, obtain an SSL certificate if needed, and deploy their API and Extensible Service Proxy (ESP).\u003c/p\u003e\n"],["\u003cp\u003eFor Compute Engine, users need to reserve a static external IP address, create an A record with their API name and the external IP, set up an instance group, and configure an HTTP(S) load balancer.\u003c/p\u003e\n"],["\u003cp\u003eFor Google Kubernetes Engine (GKE), users must configure a Kubernetes service, expose ESP as a service to get an external IP address, change this address to static, and create an A record with the API name and the static IP.\u003c/p\u003e\n"],["\u003cp\u003eAfter completing the configuration steps and DNS changes propagate, requests will be sent to the user's API through the load balancer or service.\u003c/p\u003e\n"]]],[],null,["# Serving an API from your domain name\n\n[OpenAPI](/endpoints/docs/openapi/serving-apis-from-domains \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\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/grpc/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/grpc/verify-domain-name).\n- [Name your API host name](/endpoints/docs/grpc/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/grpc/deploy-api-backend).\n\nConfigure your API project to use your domain name\n--------------------------------------------------\n\nFollow the instructions in the appropriate tab. \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/grpc/deploying-apis-subdomains)"]]