Static website in Google Cloud - how to set mainpage (when index.html is in a different folder) - google-cloud-storage

I just joined. I created a bucket for my static website. The index.html (or mainpage per google terminology) is in a different folder in the same bucket. I set my index.html as the page to show up automatically (www.example.com)
I get the website on my browser if i type exact http url including my file name - IT WORKS. But, if i type the domain name alone on the browser, i get the following error:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
I did setup my MainPage on the bucket options. HEre is my gsutil web get.
{"mainPageSuffix": "gs://www.example.co/NewHome/index.html"}
But index.html does not show up when i type only example.co in the browser. Any suggestions???

Found the answer the path is relative to home (bucket).
So this works
{"mainPageSuffix": "NewHome/index.html"}.
In case the developers of the Google-cloud for web are listening to this...
Even though the system picks up the index.html in a different folder, the images, jss etc are not pickedup. The current working directly still remains the home directory. (In the web case this could be relaxed to change the CWD based on where the mainpage suffix is pointing to. (just an opinion).

Related

MainPageSuffix for static site not working

I have searched for this question, but none of the responses help me.
Following the tutorial, I have created a new bucket (www.stepwiserefinement.co.uk) and it contains a static site, including index.html and error.html.
I have used the Console to set these as defaults for the base url and unknown files.
When I access the http://www.stepwiserefinement.co.uk URL, I get an XML listing of the files; I should be seeing index.html.
gustily correctly reports
{"mainPageSuffix": "/index.html", "notFoundPage": "/error.html"}
but if I access the domain with no path, the response is
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
<Details>
Anonymous caller does not have storage.objects.list access to the Google Cloud Storage bucket.
</Details>
</Error>
No https, no load balancer needed.
Missing something.
Suggestions please.
There's multiple issues here.
Your site still loads in HTTPS when you put it in the browser. The connection is somehow upgrading you to SSL. And if you're in SSL, you need the load balancer. As opposed to these instructions without load balancer. Maybe you have SSL turned on with your registrar or somewhere else.
I only get 404 error. Not sure how you got "Access denied". But it could also be a secondary issue because when enabled properly, no access control is present. For example, it says here under step 3 "selected Uniform for Access Control". This removes access control.
Let us know if you followed the last article completely
Edit: Also, out of curiosity, try making the bucket public (without Uniform), if it doesn't work above.

Add to home screen banner prompt not coming while fetching web manifest from server and then setting path of that inside index.html

I have created one PWA app, so while setting path of manifest in index.html statically, I am getting prompt for A2HS, But while getting manifest from server and setting the manifest href as server URL, Prompt for A2HS is not coming, from browser 3 dots I am still able to add PWA application. I initially thought that service worker is being registered first and then manifest href set, but then I did register Service worker after fetching manifest and can see in head element href for the manifest.

Google CDN Connection to CDN create nosuch Key Errors

i uploaded images to google storage bucket and i am no trying to set the CDN using the load balancer to work.
Storage Status :
Bucket Permissions : Storage Object Viewer - Reader assign to allUsers ,
Storage Legacy Bucket Reader assign To allUsers
File Status :
Share Public is set and there is a public link
Load Balancer:
Set to path /creatives/* on the host name
but i always get this msg:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
what i notice is as soon as i build the path of /creatives/* there is another path build /* direct to the backend service of the auto scale group
am i missing here any settings?
So as i discovered Google CDN + Google http Load balancer works different from other CDN.
with a regular CDN you can direct the origin to you bucket HTTP address and work on the / structure.
for example :
Google CDN Bucket URL:
googleapi.storage.com/my-bucket
Folder structure:
/1/1.jpg
Normal CDN origin will be pointing to googleapi.storage.com/my-bucket
and you will get a new service endpoint for the CDN like:
my-bucket.fastly.cdonservice.com
and this call will work:
my-bucket.fastly.cdonservice.com/1/1.jpg
but on google cloud what you are setting up is a path that is connected to the CDN service that you created on the backend part.
So this is the big difference, lets assume that you created this path rule.
host: www.googlecdnnonexplainedfeautres.com
path: /images/*
service: yourbackendservice (connected to the bucket you want to cache)
so you might assume this should work:
www.googlecdnnonexplainedfeautres.com/images/1/1.jpg.
but NO ..
after digging the logs you will find a 404 on the bucket because google will go and search this path on the bucket:
googleapi.storage.com/my-bucket/images/1/1.jpg.
wait , where did the images came ? i thought its a hook. no google take this as a static website root ( the thing you can check on and off on S3) so here its mandatory.
so how this should work ?
modify the folder structure to be like this :
Google CDN Bucket URL:
googleapi.storage.com/my-bucket
Folder structure:
images/1/1.jpg
and now you are good.
This link should work now :
www.googlecdnnonexplainedfeautres.com/images/1/1.jpg.
so before you commit a bucket to be used as CDN source for google just add another top folder that match with the path you set on the LB.
and of course .. permissions , allUsers , read and etc..
EnjoY!
You can use URL Rewrites to solve this problem.
This may not have existed back in 2017 but there's an option at least as of 2021.
Explanation:
The lb's default behavior is to pass the entire path after the host to Cloud Storage. This may seem incorrect, but it's a sane default (How is the load balancer supposed to know what part of the path you want to include or exclude?).
I was facing the same issue.
I connected mydomain.com/static/* to my cloud storage bucket static-assets.
Upon visiting mydomain.com/static/static-asset.jpg the load balancer would request cloud storage for an object with key static-assets/**static**/static-asset.jpg.
Since the object's actual key is static-assets/static-asset.jpg, this would return a NoSuchKey response.
The fix was the rewrite the path prefix of /static to /.
One way to configure this is through the Cloud Console Load Balancer UI--we can add an advanced path rule to rewrite the prefix.
Please note:
Important: The rewrite is prepended to the path as is. Full path
rewrites are not supported. HTTP(S) Load Balancing only implements
path prefix rewrites. For example, you can rewrite:
host.name/path1/resource1 to host.name/path2/resource1. You cannot
rewrite host.name/path1/resource1 to host.name/path1/resource2.
Read about URL Rewrites here.

base url redirecting for absolute urls

I'm dealing with an annoying problem. I have to make some changes to a large website, which source code is not under my control (sub-contracting). As usually I try to rebuild a local copy of the site to test my changes. The problem is now that almost all paths used in URLs for images, css, links etc. are relative paths pointing to the root directory, like
href="/style/main.css"
This is a problem because I develop on an intranet server and I put this project into a nested directory, so the URL to the project files is sth. like
http://myIntranet.com/checkout/project
What happens is that the paths from the first example don't resolve correctly. So I tried using the base tag to set the directory from which links should be resolved as
That works fine when the path is
href="style/main.css"
without the slash at the start, but fails when the slash exists, because (I think) the link is resolved from the server host, not from the URI in the tag.
So... is there any possibility to make the "/dir/file.html" links resolve from a root othe than the server root? Or do I have to manually remove all prepending slashes from the paths (urgh)?
Thanks in advance. :)
If you're doing local development on a web site you can do either of the below. Both involve moving your project in a base folder instead of working with sub folders inside your document root.
Virtual host on different port
In your web server, create another listening port and virtual host.
After restart, you can access your web server as http://localhost:81 or whatever port number you choose.
Virtual host on same port
Only create another virtual host (like above), but make sure to use named virtual hosting.
After restart, you have to add another entry in your hosts file (c:\windows\system32\drivers\etc\hosts or /etc/hosts) using a simple text editor:
127.0.0.1 localhost myproject1.self.com
The above line should already exist, so you can keep adding more names to it:
127.0.0.1 localhost myproject1.self.com myproject2.self.com
Personal preference
I like the second option, because I don't have to mess with ports and stuff like Facebook API keeps working as you expect.
I hope this all makes sense, let me know otherwise.

"URL not found" error at my localhost setup of TYPO3 website.

I have setup TYPO3 successfully on my local server. But I am having problem when clicking on any menu item: It's showing "url not found on server".
When I type in the URL manually into the browser it shows the page. It's only having problems when redirecting after clicking on a page item at any frontend website page.
That might be related to the domain config or RealURL... or both ;)
Do you use RealURL? Or do you use the standard url config?
If links to sub pages look like index.php?id=12345 you are using the standard config.
My guess is that the local DNS ("hosts file") is not configured correctly.
With the hosts file you can simulate how the web site will appear when it's online, hooked up to a "real/global" DNS. (Not quite, but in a nutshell)
So if you set up Typo3 to be reached under http://www.example.com/ you need to tell your local DNS ("hosts file") to route a request to http://www.example.com/ to your local host e.g. http://127.0.0.1/ . In that case your host file needs an entry like so:
127.0.0.1 http://www.example.com/
What Domain do you enter to reach your web site? Where do the links from the menu link to?
If you wanna know mor about the "hosts file" look here:
http://accs-net.com/hosts/how_to_use_hosts.html
If you can log in into the TYPO3 backend (/typo3/) and can access the frondend through /index.php, but not through the generated menu links, then RewriteRules for mod_rewrite don't apply.
Usually TYPO3's installer should detect this configuration and disable RealURL, which is responsible for generating such nice looking URLs (instead of index.php?id=123). It seems like this failed (or you copied everything afterwards without the .htaccess file?).
Make sure that you have TYPO3's .htaccess file in place in the root directory of your installation. If this is the case, make sure that mod_rewrite is enabled in your Apache config.