I'm trying to configure the Google Cloud loadbalancer to do the following:
I have a website running on a Wordpress machine in a VM instance which I want users to access when they enter outairnet.com.
And I have a separate html file that I want users to access when they access outairnet.com/map.
WP is running on a compute engine VM, connected to a VM instance and to a backend service. The seperate html file is on a service bucket, connected to a backend bucket.
I've triedd to configure a very simple path forwarding rule, which made sense to me. But it just adds up to anyone trying to access outairnet.com/* gets to the WP (which is fine)
but accessing outairnet.com/map doesn't point to the storage bucket with the html file, however accessing outairnet.com/index.html does point to the separate html file.
My LB config looks like this.
I think I'm on to the problem but still can't solve it.
it looks like google console adds a /* rule even when I try to delete it.
so its a /* path rule that catches everything despite having a more specific rule like /mypath/* in addition.
but after removing it is just readded automatically for some reason. why?
It's possible - there are a few steps involved such as creating a bucket with your static page, adding it as a backend service in your load balancer and creating a new path-rule in it to redirect the requests.
And now the details:
Create a new bucket - pick the name you like (outairnet-static or something that will be meaningful to you so you don't delete by accident). You can ignore all the tutorials telling that it has to have the exact name of your domain - since it will only be hosting a file accessible under outairnet.com/mylink/ it will work regardless of the name used. I tested it.
Create a directory in your bucket named exactly ax the path under which you want it to be. If you want outairnet.com/mylink/ then directory's name has to be mylink. Upload your files into that directory. Name your main index file index.html unless you want to provide full file path.
Make the bucket avaialble to everyone.
Go to your LB configuration and edit backend services; add a new backend bucket.
Go to your Host and Path Rules and configure a new path; Enter the name of your site and the path (Remember that the path value must be /mylink/*.) and select the bucket you've just created from the dropdown list.
No changes necessary for the frontend. Save the changes and in a few moments it should be working.
I just added another path rule with just "/" directing to the VM and it seemed to do it, but now the only glitch is www.outairnet.com/map is fine but outairnet.com/map without www directs to the vm and not the bucket
Related
I know there are a few threads on this issue out there but all of them have answers from 2019 where other behaviours and features were available, for example, at the time you couldn't even add a bucket as a backend service on a load balancer.
I'm trying to serve files from bucket A from mydomain.com/storage/public and bucket B from mydomain.com/storage/private which isn't an issue.
What I haven't successfully done is to rewrite the path so that I don't have to add all my files in bucket A nested in the folder /storage/public and for bucket B in /storage/private -- but rather just serve them from the root of the bucket.
I have added the following path & host rewrite rule that doesn't work:
host:
path: /*
I'm assuming this tells it to rewrite mydomain.com/storage/public/myfile.png to mydomain.com/myfile.png, but again this doesn't seem to work.
As I understand that you might have one file eg xyz, .png in public folder so your URL looks like
mydomain.com/storage/public/xyz.png
And would like to serve the file(s) from the root folder ie., mydomain.com/storage/xyz.png. You have also attempted to rewrite the paths and were not able to do so. Let me know if I captured your information correctly.
I would recommend you to modify your configuration with below steps:
Click edit on your Load balancer
Change the host and path rules :
In the left column of the screen, click Host and path rules.
Select Advanced host and path rule (URL redirect, URL rewrite).
Click the row that contains the non-default path rule,
Click the pencil icon edit for the /storage/* Route traffic to a single backend:backend name
Under Paths, delete /storage/* and add /*.
Under Action, select Route traffic to a single backend.
Click Add-on action (URL rewrite).
Leave Host rewrite blank.
Under Path prefix rewrite, enter /storage/.
Under Backend, select backend name and Click Save and Click Done.
If everything looks correct, click Update to update your HTTP load balancer.
Refer the documentation for more information.
I uploaded a website into Google cloud platform > storage and set up the DNS and it goes to google then says an error message about the bucket (I can't reproduce the error message, but it doesn't go to the right location). Google gives me a link to the website and I can get to it from: https://storage.googleapis.com/pampierce.me/index.html
but https://pampierce.me/index.html doesn't work.
Currently, the DNS CNAME is set to: c.storage.googleapis.com. What should it be set to?
Or is the problem that I shouldn't put an HTML / CSS / JS only website in Storage? If so, then where / how?
Thanks.
The issue is with the name of the bucket, this is why it is not working.
I checked the CNAME record for www.pampierce.me and it points to c.storage.googleapis.com. but pampierce.me points to 91.195.240.103. Note that www.pampierce.me is not the same as pampierce.me. This is about DNS but in general this config is okay.
Actually, the real issue is with your bucket. As well you can create a bucket with the name pampierce.me, this does not work when using Cloud Storage to host a site and for this reason the bucket should be named www.pampierce.me. This is mentioned here.
Once you have created the bucket www.pampierce.me and set all the files and steps you have already done, everything should be working fine. Also the way to access is http://www.pampierce.me/index.html (note that as before is not the same as http://pampierce.me/index.html).
Finally you will notice that I say http and not https and the reason is because Cloud Storage does not supports SSL for hosting a website
In case you may want to access using https://pampierce.me (naked domain and HTTPS), I suggest to follow this tutorial but also implies to use a Load Balancer which also means extra cost. Also the issue is with Cloud Storage and App Engine is a different product.
Let's assume one has an Amazon S3 bucket example.com configured for static hosting. In the configuration, the console allows setting an index file and an optional error file. But I'm struggling to figure out how to add another page to the site. I thought this would be straight forward but I cannot find the answer in the official documentation or on the internet.
If I want to add one more page to the static site (e.g. example.com/page2) and there is a page2.html file already in the S3 bucket at the root, where is the correct place to make this routing configuration? Can it be done through the S3 console? Or does it need to be configured through some kind of a DNS record? As a further complication, this needs to also work with and without the www in the URL.
On the DNS side I currently have the following configuration:
CNAME | WWW | www.example.com.s3-website-east-1.amazonaws.com | TTL 30 min
URL Redirect Record | # | http://www.example.com unmasked
Are you trying to access the page at example.com/page2.html or example.com/page2
If you want to access the page at example.com/page2 then create a 'folder' called page2 off the root and in that folder put a file called index.html
If you want to use example.com/page2.html, then create a file called page2.html and put it in the 'root' of the bucket.
Simply create a file called page2.html. It will be accessible via example.com/page2.html.
No routing configuration is required.
The index file alias is only used if no page is specified (eg they go to example.com/).
As for mapping www.example.com to example.com, you would create another bucket with the name www.example.com and use "Redirect requests" to point back to example.com. (If using a CNAME works for you, that's probably easier, but test it first to see if it functions as expected. See: Mapping naked domain (www.domain.com) to static website which is saved in S3)
See: Configuring a static website using a custom domain registered with Route 53 (Follow the manual steps rather than automating via CloudFormation, so you can better understand what has been configured)
I have a website hosted on a Google Cloud Storage bucket, following the instructions on https://cloud.google.com/storage/docs/hosting-static-website. The site works, but navigating to any subdirectory page directly, such as https://example.com/blog, will redirect me to https://example.com/blog/index.html, and sometimes this results in another redirect to my 404 page. If I start at https://example.com, and navigate elsewhere, the site works fine.
This is with the MainPageSuffix set to index.html and NotFoundPage set to 404.html.
If I navigate to a subdirectory page with a trailing slash at the end (e.g. https://example.com/blog/), the site works fine. I’ve also looked st the troubleshooting advice for 301s, and it running through the steps did not work for me.
Is there any way to enforce the trailing slash for GCS buckets as a static site? If not, how can I get around the issues I am seeing with redirects to index.html?
If your MainPageSuffix is index.html, when you try to access a subdirectory directly such as https:// example.com/blog as you indicated, the service try to look for the target object or https:// example.com/blog/index.html. Same is also true for https:// example.com/blog/ assuming no zero-byte object exists for /blog/. In case a zero byte empty object exists for /blog/, See the Troubleshooting topic for removing this zero byte object. When the zero byte object is removed the system will show https:// example.com/blog/index.html. If no such object exists the system will show an error page "404.html" if it is set for NotFoundPage.
In your case if you include an index.html file under the subdirectory /blog/ it should resolve the issue by displaying the https:// example.com/blog/index.html page in both scenarios https://example.com/blog or https://example.com/blog/. Alternatively you need to provide the full path to access any particular object within the subdirectory.
For further info on how subdirectory works see the following links.
How Subdirectories Work
From Recommended: Assigning specialty pages:
An index page (also called a webserver directory index is a file served to visitors when they request a URL that doesn't have an associated file. When you assign a MainPageSuffix, Cloud Storage looks for a file with that name whose prefix matches the URL the visitor requested.
For example, say you set the MainPageSuffix of your static website to index.html. Additionally, say you have no file named directory in your bucket www.example.com. In this situation, if a user requests the URL http://www.example.com/directory, Cloud Storage attempts to serve the file www.example.com/directory/index.html. If that file doesn't exist, Cloud Storage returns an error page.
The MainPageSuffix also controls the file served when users request the top level site. Continuing the above example, if a user requests http://www.example.com, Cloud Storage attempts to serve the file www.example.com/index.html.
If you are still experiencing any issues, please provide the breakdown of your website so that specific solution for your problem can be provided and also indicate what specific outcome you are expecting.
For info, I intentionally inserted a space after each http:// to avoid including so many links in this post.
I just got my custom domain name setup via AWS API Gateway, and now I have several domain names all routing to one lambda function. which just serves a webpage.
The setup looks like this:
And I have several of these with different domains that I want all to serve the same content.
Now, I'd like to add another path like /getdata or something which will just serve some data from a database instead of serving static HTML.
But when I try to add another path I get this error:
Error
Only one base path mapping is allowed if the base path is empty.
How can I have a single domain with multiple paths then?
I tried just using the wildcard path: *, and that works for multiple paths like /test or /getdata, but it doesn't work with just the domain name, and I can't tell every single user to make sure to type something in like /home everytime
Ahh I figured it out!
So, unfortunately, the page that shows you the custom domains is not where you need to be making your routes.
The correct procedure is to create an API (or use an existing API, and modify the resources) and give it a proxy resource, and a plain GET method that originates from the root path.
First, go to your API GateWay console, and create a new API.
Then once you give it a name, and choose the type (regional, or edge), it will show you the resources page
Here, you will do 2 things: Create a catch all proxy resource, and also a get resource to the root path.
Step 1: Make a catch all proxy resource:
Click Actions, and choose Create Resource
On the wizard, click Configure as proxy, and give it a name. Leave the resource path as it is. Then click create resource. The {proxy+} is notation that tells AWS that this resource should accept any path that has anything after the /. This means /test will work as well as /test/1/2/3/etc. However just / alone will not work!
Next, it will take you to this screen where you choose your integration type. We want lambda, which is the default. Make sure to select the correct region, for me the default was the right one. Then start typing in your lambda function name, and it should dynamically pop up a list of your lambda functions. select the one that you want for your application. If that doesn't work, you can copy and paste your lambda ARN from the lambda function console. Click Save.
Step 2: Make a get resource for the root path
Click the root slash at the top, right under where it says resources. Then click actions, and choose Create Method. It will pop up a little selection thing under the root slash, and there you should select GET, and then click the little checkmark.
Here, make sure to check Use Lambda Proxy Integration, and then the rest of this form should be the same as the last one you did. Just select your region, and your lambda function, and click Save.
Step 3: Deploy
Once that's done, go to actions, and choose Deploy API, give it a name for a stage, and some description, and then you are ready to attach this API to your custom domain.
Step 4: Attach
On the left tab scroll down to where it says Custom Domain Names, and create a new domain name (or attach it to an existing one if you have it)
Enter your domain name, and choose regional or edge. Then choose your certificate (there are many good guides for how to make a certificate through AWS)
Once you click save, it will look something like this:
Click Show Base Path Mappings, and then Edit.
In the path field just leave a slash, in the Destination field, choose from the dropdown the API that you just deployed. And on the right, select the stage that you made when you deployed your API.
Lastly, it will sit at initializing for a while, so while you wait for that, remember that you need to make a route53 record set for this domain, and map it to the cloudfront target URL that the API GateWay gave us. This target url looks like: www.u10dsa3s5iovdk.cloudfront.net. Copy that, and go to Route 53, Choose the hosted zone for your domain. Create a record set, and give it the same name as the domain you just created, so if you made www.example.com, in the name field of Route 53 you need to type in www. or if you made test.example.com you need to type in test. Then choose Alias: Yes, and for the Alias Target, paste in the cloudfront url from API GateWay.
When the custom domain name is done initializing, you can make calls to www.example.com as well as www.example.com/anything/else/you/want/to/put/here
Hope this helps anyone who was stuck as long as I was. Please let me know if there's anything I missed, or if something is inaccurate.
In this case you need to configure a path different to "/" for each api you need to serve through custom domain. AWS Api Gateway don't let you to serve several api into the same custom domain if you serve at least one api with no base path.