By ITUser9119
Hi, I’m testing out nginx round-robin load balancing and am fairly new to this.
1)Can I configure DNS so that I can access the webserver via a domain name instead of IP? 2)How can I check if load balancing is working? I have 2 web servers and want to know which server gets the request when a client sends the request.
This is my nginx code(very basic)
upstream web_backend {
server 10.11.12.51;
server 10.11.12.52;
}
server {
listen 80;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_backend;
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
To bind domain(s) to your server block you need to add the server_name directive. Below is an updated config.
Adding least_conn; in your upstream block allows for NGINX to more fairly distribute the load across your upstream server(s). More information on the different algorithms can be found here – http://nginx.org/en/docs/http/load_balancing.html –
The first server block redirects the non-www version of the domain to the www version.
The second block handles the www request and passes that onto your upstream server(s).
upstream web_backend {
least_conn;
server 10.11.12.51;
server 10.11.12.52;
}
server {
listen 80;
server_name yourdomain.com;
location / {
return 301 http://www.$server_name$requrst_uri;
}
}
server {
listen 80;
server_name www.yourdomain.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_backend;
}
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.