You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-43Lines changed: 42 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,34 @@
1
1
# NGINX Plus Integration with AWS Auto Scaling groups -- nginx-asg-sync
2
2
3
-
**nginx-asg-sync** allows [NGINX Plus](https://www.nginx.com/products/) to support scaling when load balancing [AWS Auto Scaling groups](http://docs.aws.amazon.com/autoscaling/latest/userguide/WhatIsAutoScaling.html): when the number of instances in an Auto Scaling group changes, nginx-asg-sync adds the new instances to the NGINX Plus configuration and removes the terminated ones.
3
+
**nginx-asg-sync** allows [NGINX Plus](https://www.nginx.com/products/) to discover instances of [AWS Auto Scaling groups](http://docs.aws.amazon.com/autoscaling/latest/userguide/WhatIsAutoScaling.html). When the number of instances in an Auto Scaling group changes, nginx-asg-sync adds the new instances to the NGINX Plus configuration and removes the terminated ones.
4
4
5
-
More details on this solution are available in the blog post [Load Balancing AWS Auto Scaling Groups with NGINX Plus](https://www.nginx.com/blog/load-balancing-aws-auto-scaling-groups-nginx-plus/).
5
+
## How It Works
6
+
nginx-asg-sync must be installed on the same EC2 instance with NGINX Plus. nginx-asg-sync constantly monitors backend Auto Scaling groups via the AWS Auto Scaling API.
7
+
When it sees that a scaling event has happened, it adds or removes the corresponding backend instances from the NGINX Plus configuration via the NGINX Plus API.
6
8
7
-
Below you will find instructions on how to use nginx-asg-sync.
9
+
**Note:** nginx-asg-sync does not scale Auto Scaling groups, it only gets the IP addresses of the instances of Auto Scaling groups.
8
10
9
-
## Contents
11
+
In the example below, NGINX Plus is configured to load balance among the instances of two Auto Scaling groups -- Backend One and Backend Two.
12
+
nginx-asg-sync, running on the same instance as NGINX Plus, ensures that whenever you scale the Auto Scaling groups, the corresponding instances are added (or removed) from the NGINX Plus configuration.
Below you will find documentation on how to use nginx-asg-sync.
17
+
18
+
## Documentation
19
+
**Note:** the documentation for **the latest stable release** is available via a link in the description of the release. See the [releases page](https://github.com/nginxinc/nginx-asg-sync/releases).
-[Building a Software Package](#building-a-software-package)
31
+
-[Support](#support)
19
32
20
33
## Supported Operating Systems
21
34
@@ -34,18 +47,14 @@ nginx-asg-sync uses the AWS API to get the list of IP addresses of the instances
34
47
1.[Create an IAM role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) and attach the predefined `AmazonEC2ReadOnlyAccess` policy to it. This policy allows read-only access to EC2 APIs.
35
48
1. When you launch the NGINX Plus instance, add this IAM role to the instance.
36
49
37
-
Alternatively, you can use the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environmental variables to provide credentials to nginx-asg-sync.
38
-
39
50
## Installation
40
51
41
-
To install nginx-asg-sync:
42
-
43
-
1. Download a software package for your OS with the latest version of nginx-asg-sync from the [Releases page](https://github.com/nginxinc/nginx-asg-sync/releases).
44
-
1. Install the package:
45
-
46
-
For Amazon Linux or CentOS/RHEL, run: `$ sudo rpm -i <package-name>.rpm`
47
-
48
-
For Ubuntu, run: `$ sudo dpkg -i <package-name>.deb`
52
+
1. Get a software package for your OS:
53
+
* For a stable release, download a package from the [releases page](https://github.com/nginxinc/nginx-asg-sync/releases).
54
+
* For the latest source code from the master branch, build a software package by following [these instructions](#building-a-software-package).
55
+
2. Install the package:
56
+
* For Amazon Linux or CentOS/RHEL, run: `$ sudo rpm -i <package-name>.rpm`
57
+
* For Ubuntu, run: `$ sudo dpkg -i <package-name>.deb`
49
58
50
59
## Configuration
51
60
@@ -54,6 +63,8 @@ As an example, we configure NGINX Plus to load balance two AWS Auto Scaling grou
54
63
* Requests for /backend-one go to Backend One group.
55
64
* Requests for /backend-two go to Backend Two group.
56
65
66
+
This example corresponds to [the diagram](#how-it-works) at the top of this README.
67
+
57
68
### NGINX Plus Configuration
58
69
59
70
```nginx
@@ -86,40 +97,28 @@ server {
86
97
server {
87
98
listen 8080;
88
99
89
-
root /usr/share/nginx/html;
90
-
91
-
location = / {
92
-
return 302 /status.html;
93
-
}
94
-
95
-
location = /status.html {
96
-
}
97
-
98
-
location /status {
99
-
access_log off;
100
-
status;
100
+
location /api {
101
+
api write=on;
101
102
}
102
103
103
-
location /upstream_conf {
104
-
upstream_conf;
104
+
location /dashboard.html {
105
+
root /usr/share/nginx/html;
105
106
}
106
107
}
107
108
```
108
109
109
110
* We declare two upstream groups – **backend-one** and **backend-two**, which correspond to our Auto Scaling groups. However, we do not add any servers to the upstream groups, because the servers will be added by nginx-aws-sync. The `state` directive names the file where the dynamically configurable list of servers is stored, enabling it to persist across restarts of NGINX Plus.
110
111
* We define a virtual server that listens on port 80. NGINX Plus passes requests for **/backend-one** to the instances of the Backend One group, and requests for **/backend-two** to the instances of the Backend Two group.
111
-
* We define a second virtual server listening on port 8080 and configure the NGINX Plus APIs on it, which are required by nginx-asg-sync:
112
-
* The on-the-fly API is available at **127.0.0.1:8080/upstream_conf**
113
-
* The status API is available at **127.0.0.1:8080/status**
112
+
* We define a second virtual server listening on port 8080 and configure the NGINX Plus API on it, which is required by nginx-asg-sync:
113
+
* The API is available at **127.0.0.1:8080/api**
114
114
115
115
### nginx-asg-sync Configuration
116
116
117
117
nginx-asg-sync is configured in the file **aws.yaml** in the **/etc/nginx** folder. For our example, we define the following configuration:
* The `region` key defines the AWS region where we deploy NGINX Plus and the Auto Scaling groups.
136
-
* The `upstream_conf` and the `status_endpoint` keys define the NGINX Plus API endpoints.
135
+
* The `api_endpoint` key defines the NGINX Plus API endpoint.
137
136
* The `sync_interval_in_seconds` key defines the synchronization interval: nginx-asg-sync checks for scaling updates every 5 seconds.
138
137
* The `upstreams` key defines the list of upstream groups. For each upstream group we specify:
139
138
* `name` – The name we specified for the upstream block in the NGINX Plus configuration.
140
139
* `autoscaling_group` – The name of the corresponding Auto Scaling group.
141
140
* `port` – The port on which our backend applications are exposed.
142
-
* `protocol` – The protocol of the traffic NGINX Plus load balances to the backend application, here `http`. If the application uses TCP/UDP, specify `stream` instead.
141
+
* `kind` – The protocol of the traffic NGINX Plus load balances to the backend application, here `http`. If the application uses TCP/UDP, specify `stream` instead.
0 commit comments