问题
I have a domain bar.com on CloudFlare that is linked to a site hosted on Google Cloud. I can create a new A record on CloudFlare for a subdomain "foo", but how do I map that to bar.com/foo on Google Cloud?
I'm not sure if this question makes sense. Basically, I have a site that is hosted on standard server which I am moving to Google Cloud. On the standard server, I have CPanel which handles creation of subdomains (of which are added to CloudFlare's DNS). I'm not sure how this process is replicated on Google Cloud.
Any help is greatly appreciated!
回答1:
First of all, you need to create another Google Cloud Storage (GCS) bucket to host your subdomain.
- Go to your GCS dashboard.
- Create a new bucket with name as your full subdomain url: foo.bar.com
- GCS will ask for you to verify you are the owner of that domain. If you already verified bar.com, you don't need to do anything else, otherwise follow this tutorial.
- Upload your files to bucket.
- Make your bucket public.
- Finally, configure your bucket website settings.
Now, we can proceed to CloudFlare.
- Go to your CloudFlare dashboard.
- Open the DNS settings of your domain: bar.com
- Add a new record with this settings:
- Type: CNAME
- Name: foo (your subdomain)
- Value: c.storage.googleapis.com (default DNS address of GCS)
- TTL: Automatic TTL (or anything else, doesn't matter)
- Wait a few minutes, then open up your subdomain url.
- Voilà! Hope this helps.
回答2:
So you can create subdomains so you have: bar.foo.com
but you can't create a DNS record for foo.com/bar
. Enter CloudFlare, in CloudFlare you can set-up a page rule to redirect foo.com/bar
to bar.foo.com
.
You need to ensure foo.com
is routed through CloudFlare and in DNS settings the cloud is orange. Then you need to make sure the DNS record for bar.foo.com
is pointing to Google's servers instead of your cPanel.
Have fun!
回答3:
I found the solution, it's basically to manually create a entry. I was confused a little because I am using the Bitnami LAMP deployment.
In case this will help somebody in the future, if you're using Bitnami's LAMP, this is how you create subdomain(s)
Open the file /opt/bitnami/apache2/conf/bitnami/bitnami.conf
and add the following:
<VirtualHost *:80>
ServerName foo.bar.com
ServerAdmin foo@bar.com
DocumentRoot "/opt/bitnami/apache2/htdocs/foo"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/opt/bitnami/apache2/htdocs/foo">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
</VirtualHost>
where foo
is the subdomain. Then restart Apache sudo /opt/bitnami/ctlscript.sh restart apache
If you are using CloudFlare, you will need to add an A entry into your DNS, with foo
as the name, and your Bitnami/Google Cloud deployment's IP. You may leave the status as bypass (grey cloud) or active (orange cloud), it doesn't matter.
Hope it helps somebody!
来源:https://stackoverflow.com/questions/33115300/creating-a-subdomain-with-google-cloud-cloudflare