Reputation: 5053
I have multiple domain names and I want all of them point to the same webserver I have on google compute engine instance, how can I do that?
Upvotes: 1
Views: 2630
Reputation: 31
You don't need to have a separate static IP address per website—you can serve an arbitrary number of sites from a single VM by using a feature such as Apache virtual hosts which let you serve a different site depending on the hostname that is requested by the user.
As Per the Google Compute Engine docs on static IP addresses: "An instance can have only one external IP address. If it already has an external IP address, you must first remove that address by deleting the old access configuration, then adding a new access configuration with the new external IP address"
but using Protocol Forwarding
You can archive multiple external IPs for one VM instance, but need some configuration. 1) By default, VM will be assigned with an ephemeral external IP, you can promote it to static external IP, which will remain unchanged after stop and restart. 2) Extra external IPs have to be attached to ForwardingRules which target the VM. You can use (or promote to) static IPs as well.
The command you may want to use would be:
1) Create a TargetInstance for your VM instance:
gcloud compute target-instances create <target-instance-name> --instance <instance-name> --zone=<zone>
2) Create a ForwardingRule pointing to the TargetInstance:
gcloud compute forwarding-rules create <forwarding-rule-name> --target-instance=<target-instance-name> --ip-protocol=TCP --ports=<ports>
Upvotes: 3