Today I’d demonstrate how to setup the simplest reverse proxy and load balancer in OpenResty Edge.

Set up a Simplest Reverse Proxy and Load Balancer_java

We manage all the gateway server nodes and their configurations in a central place, the Edge Admin web console.

Set up a Simplest Reverse Proxy and Load Balancer_java_02

Let’s go to a web console of OpenResty Edge. This is our sample deployment of the console. Every user would have their own deployment.

Let’s login using our user name and password.

Set up a Simplest Reverse Proxy and Load Balancer_java_03

Other authentication methods are also configurable.

Sign in now.

Set up a Simplest Reverse Proxy and Load Balancer_java_04

We’re now at the application list page. There are many existing applications we created previously. Each application is like a virtual host or virtual server in the same gateway.

Here we’d create a new application.

Set up a Simplest Reverse Proxy and Load Balancer_java_05

We will just create one of the HTTP type. It is the default.

Set up a Simplest Reverse Proxy and Load Balancer_java_06

We assign a single domain, test-edge.com, to this application.

Set up a Simplest Reverse Proxy and Load Balancer_java_07

We may add more domains, including wildcard domains.

Set up a Simplest Reverse Proxy and Load Balancer_java_08

We only care about the 80 port in this example.

Set up a Simplest Reverse Proxy and Load Balancer_java_09

Let’s create this application!

Set up a Simplest Reverse Proxy and Load Balancer_java_10

Now we are inside this new application. It’s empty.

Let’s go to the Upstreams page.

Set up a Simplest Reverse Proxy and Load Balancer_java_11

Obviously, we currently have no upstreams defined.

Create a new upstream for our backend servers.

Set up a Simplest Reverse Proxy and Load Balancer_java_12

We give this upstream a name, say, my_backend.

Set up a Simplest Reverse Proxy and Load Balancer_java_13

For simplicity, we just use the HTTP protocol here.

Set up a Simplest Reverse Proxy and Load Balancer_java_14

We may always want to use HTTPS for the real thing.

Set up a Simplest Reverse Proxy and Load Balancer_java_15

Here we need the backend server’s IP address.

Set up a Simplest Reverse Proxy and Load Balancer_java_16

We’ve already prepared a sample backend server at this IP address.

Set up a Simplest Reverse Proxy and Load Balancer_java_17

It simply returns the default index page of the open source OpenResty server software.

It could be anything that speaks HTTP.

Set up a Simplest Reverse Proxy and Load Balancer_java_18

We can now fill out the host field for the backend server.

Set up a Simplest Reverse Proxy and Load Balancer_java_19We keep the 80 port intact.

Set up a Simplest Reverse Proxy and Load Balancer_java_20

We may add more servers to this upstream in the future.

Set up a Simplest Reverse Proxy and Load Balancer_java_21

Now save this upstream.

Set up a Simplest Reverse Proxy and Load Balancer_java_22

We can see this my_backend upstream is already there.

Set up a Simplest Reverse Proxy and Load Balancer_java_23

Now let’s create a new page rule to actually make use of this upstream.

Set up a Simplest Reverse Proxy and Load Balancer_java_24

We currently don’t have any page rules defined.

Create a new page rule.

Set up a Simplest Reverse Proxy and Load Balancer_java_25

For this page rule, we do not specify a condition. This way it will apply to all incoming requests.

Set up a Simplest Reverse Proxy and Load Balancer_java_26

We could, however, limit this proxy page rule to certain requests only.

Set up a Simplest Reverse Proxy and Load Balancer_java_27

We disable the condition again.

Set up a Simplest Reverse Proxy and Load Balancer_java_28

Let’s add a proxy target here.

Set up a Simplest Reverse Proxy and Load Balancer_java_29

Let’s choose an upstream.

Set up a Simplest Reverse Proxy and Load Balancer_java_30

Here we have our newly created upstream present.

Set up a Simplest Reverse Proxy and Load Balancer_java_31

We also have some pre-defined global upstreams. They can be reused by all the applications including this one.

Set up a Simplest Reverse Proxy and Load Balancer_java_32

We select our my_backend upstream.

Set up a Simplest Reverse Proxy and Load Balancer_java_33

Our upstream has only one server.

So the balancing policy does not really matter here.

Set up a Simplest Reverse Proxy and Load Balancer_java_34

We’d just keep the default round robin policy.

We may also want to enable caching of the responses. We’ll cover this topic in another video.

Set up a Simplest Reverse Proxy and Load Balancer_java_35

Finally, create this rule for real.

Set up a Simplest Reverse Proxy and Load Balancer_java_36

We can see the proxy page rule is already listed on the page rule list.

Set up a Simplest Reverse Proxy and Load Balancer_java_37

The last step is to make a new configuration release. It will push out our pending changes to all our gateway servers.

Set up a Simplest Reverse Proxy and Load Balancer_java_38

Let’s click on this link to make a new release.

Set up a Simplest Reverse Proxy and Load Balancer_java_39

We have a chance to review our changes before pushing them out.

This is our first change.

Set up a Simplest Reverse Proxy and Load Balancer_java_40

It is our addition of the my_backend upstream.

Set up a Simplest Reverse Proxy and Load Balancer_java_41

This is our second change.

Set up a Simplest Reverse Proxy and Load Balancer_java_42

Set up a Simplest Reverse Proxy and Load Balancer_java_43This is indeed our proxy page rule.

Now we make a release to all our gateway servers.

Set up a Simplest Reverse Proxy and Load Balancer_java_44

Ship it!

Set up a Simplest Reverse Proxy and Load Balancer_java_45

We can watch the configuration synchronization progress at real time. It is pushed out to the whole gateway network.

Set up a Simplest Reverse Proxy and Load Balancer_java_46

Now it is fully synchronized. As we can see, this sample deployment has 13 servers in the gateway network.

We do incremental config synchronization across the whole network.

We live-update config on the request level. None of the application-level configuration changes require server reload, restart, or binary upgrade. So it is very scalable even when you have many different users making frequent releases.

Set up a Simplest Reverse Proxy and Load Balancer_java_47

We can also check all the gateway servers grouped by clusters.

Set up a Simplest Reverse Proxy and Load Balancer_java_48

This is just our sample deployment around the world.

Set up a Simplest Reverse Proxy and Load Balancer_java_49

Our users are free to deploy their gateway servers anywhere they like. Or spanning different clouds and hosting services.

Set up a Simplest Reverse Proxy and Load Balancer_java_50

This column shows the configuration synchronization status for each gateway server.

Set up a Simplest Reverse Proxy and Load Balancer_java_51

We can test a gateway server near San Francisco here.

Set up a Simplest Reverse Proxy and Load Balancer_java_52

Its public IP address is this.

Set up a Simplest Reverse Proxy and Load Balancer_java_53

We copy this IP address to test this server directly.

On the terminal, we can use curl to test this San Francisco gateway server.

1
curl -sS -H 'Host: test-edge.com' 'http://138.68.231.133/' | less

Set up a Simplest Reverse Proxy and Load Balancer_java_54

Note that we specify the Host request header. This is because the same server is serving many different virtual hosts.

Send the request.

Set up a Simplest Reverse Proxy and Load Balancer_java_55

It works as expected! We got the default OpenResty index page just like accessing the backend server directly.

We can check the response header too via the -I option of curl.

1
curl -I -H 'Host: test-edge.com' 'http://138.68.231.133/'

Set up a Simplest Reverse Proxy and Load Balancer_java_56

There are some headers created by the OpenResty Edge gateway software.

Alternatively, we could bind the IP address to the host name in this local /etc/hosts file. Then we’ll be able to point a web browser to this domain directly.

1
cat /etc/hosts

Set up a Simplest Reverse Proxy and Load Balancer_java_57

For the real setup, we should add the gateway server IP addresses to our DNS name servers.

1
dig test-edge.com

Here we haven’t configured this domain’s DNS records yet. We’ll demonstrate it in another video.

Set up a Simplest Reverse Proxy and Load Balancer_java_58

OpenResty Edge can also work as an authoritative DNS server network at the same time.

Set up a Simplest Reverse Proxy and Load Balancer_java_59

This is optional though. The user could still choose to use 3rd-party DNS name servers. This is what I’d like to cover today.

Set up a Simplest Reverse Proxy and Load Balancer_java_60

If you like this tutorial, please subscribe to this blog site and/or our Vimeo account and/or ourYouTube channel. Thank you!

About This Article and Associated Video

This article and its associated video are both generated automatically from a simple screenplay file.

Manage all your application's traffic via OpenResty Edge

About The Author

Yichun Zhang is the creator of the OpenResty® open source project. He is also the founder and CEO of the OpenResty Inc. company. He contributed a dozen open source Nginx 3rd-party modules, quite some Nginx and LuaJIT core patches, and designed products like OpenResty XRay and OpenResty Edge.

Translations

We provide the Chinese translation for this article on blog.openresty.com.cn. We welcome interested readers to contribute translations in other natural languages as long as the full article is translated without any omissions. We thank them in advance.

We are hiring

We always welcome talented and enthusiastic engineers to join our team at OpenResty Inc. to explore various open source software’s internals and build powerful analyzers and visualizers for real world applications built atop the open source software. If you are interested, please send your resume totalents@openresty.com . Thank you!

Try out OpenResty Edge yourself