The simplest method with NGINX to do load balancing is to have two webservers serving both the same content and have them act equally in a cluster. To achieve this you need to define the servers in the cluster and then let the proxy_pass definition point to the cluster definition.
A cluster is defined using the upstream section within the HTTP section like this
upstream main {
server 192.192.23.92:80 weight=30;
server 192.192.23.93:8000;
} And you can point to it in the server section like this:
server {
listen 192.192.23.189:80
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://main;
}
}
As you can see from above, you can provide a weight, describing which server should get the higher load.
You can control the behavior of the proxy and when and how it treats the webserver down / hanging with the proxy_*_timeout settings. These settings are per server, but can also be given per location
server {
# default:
#proxy_next_upstream error timeout invalid_header;
proxy_connect_timeout 5;
proxy_send_timeout 5;
proxy_read_timeout 15;
location /longreportpage {
proxy_pass ...
proxy_connect_timeout 5;
proxy_send_timeout 5;
proxy_read_timeout 60;
}
}
The example above is used for a server which occasionally hangs (like AOLserver has the tendency to do). The connect_timeout is used to determine how long we wait for a connection to come back. The read timeout determines, once a connection has been established, how long the pages may take to be delivered fully.
This is why we have (for a report page that takes up a long time) a longer read_timeout, as the report takes longer on the server to finish.
Load balancing OpenACS
If you are load balancing OpenACS here are a couple of things to keep in mind:
- Use OpenACS 5.4. Previous versions do not have support for dynamic sitemaps
-
Configure the cluster section in the acs-kernel parameters. Namely:
- CanonicalServer: Which is the mainserver (192.168.23.92)
- ClusterEnabled: Should be 1
- ClusterPeerIP and ClusterAuthorizedP: Should be all servers from above
-
Make sure to use permission caching
- Make sure none of your custom packages use acs_permission__grant or acs_permission__revoke calls in PL/SQL and that you do not insert into acs_permissions directly (or delete from it). This is bad coding anyways with the new standards.
- Turn on PermissionCacheP in the acs-kernel parameters by setting it to "1"
- Once done, restart your server.
