how to install Let\u2019s Encrypt on nginx<\/a>.<\/p>\n\n\n\nUsing encryption with a load balancer is easier than you might think. All you need to do is to add another server section to your load balancer configuration file which listens to HTTPS traffic at port 443 with SSL. \u00a0Then set up a proxy_pass to your upstream segment like with the HTTP in the previous example above.<\/p>\n\n\n\n
Open your configuration file again for editing.<\/p>\n\n\n\n
sudo nano \/etc\/nginx\/conf.d\/load-balancer.conf<\/pre>\n\n\n\nThen add the following server segment to the end of the file.<\/p>\n\n\n\n
server {\n listen 443 ssl;\n server_name domain_name<\/span>;\n ssl_certificate \/etc\/letsencrypt\/live\/domain_name<\/span>\/cert.pem;\n ssl_certificate_key \/etc\/letsencrypt\/live\/domain_name<\/span>\/privkey.pem;\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n\n location \/ {\n proxy_pass http:\/\/backend;\n }\n}<\/pre>\n\n\n\nThen save the file, exit the editor and restart nginx again.<\/p>\n\n\n\n
sudo systemctl restart nginx<\/pre>\n\n\n\nSetting up encryption at your load balancer when you are using private network connections to your back end has some great advantages.<\/p>\n\n\n\n
\n- As only your UpCloud servers have access to your private network, it allows you to terminate the SSL at the load balancer and thus only pass forward HTTP connections.<\/li>\n\n\n\n
- It also greatly simplifies your certificate management. You can obtain and renew the certificates from a single host.<\/li>\n<\/ul>\n\n\n\n
With the HTTPS-enabled, you also have the option to enforce encryption on all connections to your load balancer. Simply update your server segment by listening to port 80 with a server name and a redirection to your HTTPS port. Then remove or comment out the location<\/em> portion as it\u2019s no longer needed. See the example below.<\/p>\n\n\n\nserver {\n listen 80;\n server_name domain_name<\/span>;\n return 301 https:\/\/$server_name$request_uri;\n\n #location \/ {\n # proxy_pass http:\/\/backend;\n #}\n}<\/pre>\n\n\n\nSave the file again after you have made the changes. Then restart nginx.<\/p>\n\n\n\n
sudo systemctl restart nginx<\/pre>\n\n\n\nNow all connections to your load balancer will be served over an encrypted HTTPS connection. Requests to the unencrypted HTTP will be redirected to use HTTPS as well. This provides a seamless transition into encryption. Nothing is required from your visitors.<\/p>\n\n\n\n
Health checks<\/h2>\n\n\n\n
In order to know which servers are available, Nginx\u2019s implementations of reverse proxy include passive server health checks. If a server fails to respond to a request or replies with an error, nginx will note the server has failed. It will try to avoid forwarding connections to that server for a time.<\/p>\n\n\n\n
The number of consecutive unsuccessful connection attempts within a certain time period can be defined in the load balancer configuration file. Set a parameter max_fails<\/em> to the server lines. By default, when no max_fails<\/em> is specified, this value is set to 1. Optionally setting the max_fails<\/em> to 0 will disable health checks to that server.<\/p>\n\n\n\nIf max_fails<\/em> is set to a value greater than 1 the subsequent fails must happen within a specific time frame for the fails to count. This time frame is specified by a parameter fail_timeout<\/em>, which also defines how long the server should be considered failed. By default, the fail_timeout<\/em> is set to 10 seconds.<\/p>\n\n\n\nAfter a server is marked failed and the time set by fail_timeout<\/em> has passed, nginx will begin to gracefully probe the server with client requests. If the probes return successful, the server is again marked live and included in the load balancing as normal.<\/p>\n\n\n\nupstream backend {\n server 10.1.0.101 weight=5;\n server 10.1.0.102 max_fails=3 fail_timeout=30s;\n server 10.1.0.103;\n}<\/pre>\n\n\n\nUse the health checks. They allow you to adapt your server back-end to the current demand by powering up or down hosts as required. When you start up additional servers during high traffic, it can easily increase your application performance when new resources become automatically available to your load balancer.<\/p>\n\n\n\n
Conclusions on the advantages of load balancing<\/h2>\n\n\n\n
If you wish to improve your web application performance and availability, a load balancer is definitely something to consider. Nginx is powerful yet relatively simple to set up to load balance a web server. Together with an easy encryption solution, such as the Let\u2019s Encrypt client, it makes for a great front-end to your web farm. Check out the documentation for upstream<\/a> over at nginx.org to learn more.<\/p>\n\n\n\nWhen you are using multiple hosts protects your web service with redundancy, but the load balancer itself can still leave a single point of failure. You can further improve high availability when you set up a floating IP between multiple load balancers. Find out more in our article on\u00a0floating IPs on UpCloud<\/a>.<\/p>\n","protected":false},"featured_media":27387,"comment_status":"open","ping_status":"closed","template":"","community-category":[111,115],"class_list":["post-24654","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry","community-category-networking","community-category-load-balancing"],"acf":[],"_links":{"self":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial\/24654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/types\/tutorial"}],"replies":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/comments?post=24654"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media\/27387"}],"wp:attachment":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media?parent=24654"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/community-category?post=24654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}