I am using a magento application and I need to cache only the "/media" path where images are stored on Google Cloud CDN.
Actually I've configured one instance group where my VM is running the whole website application and enabled Google Cloud CDN via the checkbox on the backend part.
It appears that every http request are send to Google Cloud CDN.
How to cache only the media path files ?
You should use separate backends and the URL Map feature of the HTTP Load Balancer.
Based on URL Map, the Target HTTP Proxy will check each request and determine the appropriate backend service for the request. This way you can enable or disable Cloud CDN use for a particular backend (which means for a particular URL) with a single checkbox.
The Host and path rules are configured as part of the HTTP Load Balancer in the Cloud Console menu:
GCP Navigation => Networking => Network Services => Load balancing
=> Create load balancer => HTTP(S) Load Balancing => Start configuration
=> From Internet to my VMs => Host and path rules
Load Balancing > Doc > URL maps overview
Load Balancing > Doc > Using URL maps
Related
We are using Akamai to route requests from internet to our network. I do not have access to the Akamai configurations/settings to verify how it has been set up or what all features we use. As per information I have, we are using Akamai Sureroute to set up redirection like below -
myapp.company.com (apps public URL) > Akamai Edge Server > Akamai Sureroute path > company network load balancer > myapp server
Now we have two versions of this "myapp". One running in cloud and another on-prem. Would the below be possible to set up in Akamai -
Public URL for accessing both the cloud and on-prem versions should remain the same i.e. myapp.company.com.
Based on the path, Akamai should be able to route the request either to cloud load balancer or on-prem load balancer.
For eg: myapp.company.com/path1 should go to cloud load balancer > cloud myapp
myapp.company.com/path2 should go to on-prem load balancer > on-prem myapp
Yes, it's possible. Akamai configurations allow to change the route to origin servers. With using the match conditions, users can go to the different origin servers.
Matches (Path is available for the match condition)
https://techdocs.akamai.com/property-mgr/docs/matches
Add your origin server (Origin Server can be added for the specific condition)
https://techdocs.akamai.com/property-mgr/docs/add-an-origin-server-to-your-property
I have two services running Cloud Run such as api1 and api2.
I set up a global external HTTP(S) load balancer (classic) in GCP to route the path to both services.
such as
Paths
Action
Backend
/api1/*
Route traffic to a single backend
service-api1
/api2/*
Route traffic to a single backend
service-api2
When I send a request mydomain/api1/aaa/ccc/, api1 get the request url as mydomain/api1/aaa/ccc/
When I send a request mydomain/api2/ddd/eee/, api2 get the request url as mydomain/api2/ddd/eee/
Is there a way to rewrite the incoming request for api1, so that api1 will see the request as mydomain/aaa/ccc/?
This also apply to api2, so api2 will see the request as mydomain/ddd/eee/
From the Rewrite documentation,
The load balancer provides the following mutually exclusive primary
actions:
Reads the incoming URL in the request.
Replaces the host, the path, or both the host and the path, transforming the URL before directing traffic to the backend service
or backend bucket.
I think there is a way, but I don't manage to make it work.
Any advice?
In load balancing console page
Select Advanced host and path rule (URL redirect, URL rewrite) in Host and path rules
Add a path rule and edit path rule as below (show Add-On action)
Save and update the changes.
When you send a request mydomain/api1/aaa/ccc/, api1 will see the request as mydomain/aaa/ccc/.
I'm setting up React app frontend with Google Cloud Storage and Loadbalancer. During build, index.html and javascript file is uploaded into cloud storage. Loadbalancer points to backend bucket. I can now access react app if I go to http://(loadbalancerip)/index.html
I want to react to handle all routing, and I also want our user to access site via arbitrary path (eg http://(loadbalancerip)/user/details). Is there a way to achieve this with GCP load balancer? Basically I want it to always serve "index.html" regardless of path user is accessing.
I confirmed with GCP support that unfortunately it's not supported. Here is a open feature request https://issuetracker.google.com/issues/194125076
You can achieve this by configuring the website settings on the bucket. Configure the 404 page to serve index.html. When the user hits any random route, they will be served index.html. The only downside I can see is you do get a 404 error in the console, but that doesn't seem to affect operation at all.
My loadbalancer is configured with only the default rule, serving all traffic to the bucket backend (no additional url map rules).
What's happening here is that your load balancer is trying to serve the path (and therefore the associated index.html file) to your users but of course in react there is only one index.html and all the routes within it are controlled by the JS router.
What you can do with cloud storage is assign a "not found" or error page, as mentioned in another answer, where you configure what happens if the file eg, /blog/my_post that the user tries to visit doesn't exist. GCP calls these kinds pages "specialty pages".
You can configure a specialty page, as discussed here:
https://cloud.google.com/storage/docs/static-website#specialty_pages
Hope this helps!
Assuming you are using HTTP(S) External Load Balancer, what you are looking for is URL rewrite.
I would like to setup a HTTPS load balancer to serve both static content from a storage bucket and also point to a number of cloud run services.
The setup I am trying to achieve looks like the following:
// prod
api.example.com/serviceA -> cloud run: serviceA
api.example.com/serviceB -> cloud run: serviceB
cdn.example.com/cat.jpg -> storage bucket: cats
// dev
api-dev.example.com/serviceA -> cloud run: serviceA
api-dev.example.com/serviceB -> cloud run: serviceB
cdn-dev.example.com/cat.jpg -> storage bucket: cats-dev
The dev & prod environments are separated by projects in my case.
I have followed this guide as to how to setup this configuration.
However I am unable to resolved the various services. It is not 100% clear how the following elements interact:
url map
url mask
custom domain mapping in cloud run itself VS at the load balancer level
Please help!
Sure, it can be confusing!
URL Map: it's plugged on the Load Balancer to route a URL to a backend (Bucket, (un)Managed instance group (MIG), Network Endpoint Group (NEG)). For example the /static/ is routed to a bucket, the others to a serverless NEG
URL Mask: it's plugged on the serverless NEG. You can define a template on the URL Name to extract the service name (and tag) from the URL itself. It requires to have a dependency between your site structure and your Cloud Run service naming.
Summary
The URL Map is the first pass routing to the serverless NEG. The serverless NEG apply the URL mask to route the request to the correct service.
Custom domain mapping
On a single Cloud Run service you can apply a custom domain to reach it directly. In this case, you have no load balancing, you reach directly only one service deployed on Cloud Run.
I hope to be clear!!
I just finished setting up a load balancer with a few backend servers serving an API, I tried to hit it via https and discovered I need to set the CORS headers
but for the life of me no Googling has turned up anything. My setup roughly is a main service (actually hosted in aws for now) at https://www.example.com, then the api hosted at https://api.example.com on Google Cloud.
How can I set the load balancer COS such that I can hit api.example.com from the client side js on www.example.com
Is there even a way?
your backend server, at https://api.example.com should set the CORS headers. it's a browser security feature, the browser is at https://example.com but makes AJAX requests to a different domain.
set the headers from the backend application, it is not related to the load balancer (unless it re-writes headers).
read more about CORS - http://restlet.com/company/blog/2015/12/15/understanding-and-using-cors/