By Vikram Godse, Solution Architect
Alibaba Cloud Cloud Enterprise Network (CEN) provides connectivity to Alibaba Cloud Virtual Private Clouds (VPCs) across the globe. This provides low latency bandwidth in addition to cross border connectivity to workloads from any international Alibaba Cloud Region into Alibaba Cloud in China
For users who have their apps built around external APIs, there is a bit of configuration required to get it working from China. This article shows how to configure a Reverse Proxy to access external API's from China over Alibaba Cloud CEN.
This approach is only to showcase accessing the custom API's developed by an organization and hosted on Google API Gateway. In the long term, it is recommended that the custom API's be moved to Alibaba Cloud API Gateway.
Note: This article is for demo purposes only. All services hosted in China shall comply with local regulations.
The diagram above depicts the overall connectivity between the Alibaba Cloud regions between Beijing and London and the connectivity to Google API over the internet
Setup two hostnames in the /etc/hosts file on the Beijing server pointing to the London server for eg.
These hostnames will be the Virtual hosts that we will configure on the London Webserver, one each for the Google Translate and Text-to-Speech API's
Install Apache on the Centos Server in London
The modules that are needed to use Apache as a reverse proxy include mod_proxy itself and several of its add-on modules, which extend its functionality to support different network protocols. Specifically, we will be using:
mod_proxy, the main proxy module Apache module for redirecting connections; it allows Apache to act as a gateway to the underlying application servers.
mod_proxy_http, which adds support for proxying HTTP connections.
mod_lbmethod_byrequests, which add load balancing features for multiple backend servers.
All these modules are enabled by default, but we can check the modules installed
If any of the modules are not listed you can enable them by editing the /etc/httpd/conf.modules.d/00-proxy.conf
And un-commenting the required modules by removing the #
Save the file and then restart the httpd service
For SSL to be supported you need to install mod_ssl
Setup two virtual hosts one for the "Google Translate API" and another for the "Text-to-Speech" API
Create an Apache Config file in the /etc/httpd/conf.d/google-translate.conf and make the following entries
The request for google translate will be received by this virtual host "translate.xxxxxlondon.com" over the CEN, which is in London and it will proxy the request to Google Translate over https using the Google API URL https://translate.googleapis.com It will forward the URL context as it has received from the request.
An example request to translate some content from English to German is shown in the following diagram
We can create another Virtual host for Google-Text-to-Speech API
Create another virtual host by creating another configuration file /etc/httpd/conf.d/textospeech.conf and make the following entries
Restart the httpd server after making the virtual host entry.
Now from the server in Beijing when we have to call the Text-to-Speech API we will call https://texttospeech.xxxxxlondon.com/ which is our reverse proxy virtual host in London.
This reverse proxy will proxy the request to https://texttospeech.googleapis.com/
It will include the URL context that is received in the host header and forward it to google.
Following is a sample call that will convert some text in French to a voice file in base64 text format which can be decoded to generate the MP3 voice file
The voice file in base64 format looks as follows
Using base64 we can decode the file to a binary mp3 format audio file
The output file is as the audio.mp3 file
In this article, we showed the configuration for accessing Google API's from Alibaba Cloud in China using Cloud Enterprise Network (CEN). However this exercise has been created for users who are using googleapi to host their custom API's outside China and want to use the same API's in China. You are recommended to move the API's to Alibaba Cloud API Gateway in the long term.
Alibaba Cloud New Products - June 3, 2020
Alibaba Clouder - May 24, 2019
AlibabaCloud_Network - January 23, 2020
Alibaba Clouder - March 21, 2019
Alibaba Clouder - June 18, 2020
Alibaba Clouder - April 30, 2020
An end-to-end software-defined network solution for multinational enterprises.Learn More
A global network for rapidly building a distributed business system and hybrid cloud to help users create a network with enterprise level-scalability and the communication capabilities of a cloud networkLearn More
Connect your business globally with our stable network anytime anywhere.Learn More
API Gateway provides you with high-performance and high-availability API hosting services to deploy and release your APIs on Alibaba Cloud products.Learn More
More Posts by Alibaba Clouder