• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Nginx for Newbie: setting up upstream directive

December 18, 2023

Nginx for Newbie: Setting Up Upstream Directive

Nginx is a powerful web server and reverse proxy server that is widely used in the hosting industry. It offers high performance, scalability, and flexibility, making it an excellent choice for hosting websites and applications. One of the key features of Nginx is the ability to set up an upstream directive, which allows you to distribute incoming requests to multiple backend servers.

What is an Upstream Directive?

In Nginx, an upstream directive is used to define a group of backend servers that will handle incoming requests. It acts as a load balancer, distributing the traffic among the servers based on various algorithms such as round-robin, least connections, IP hash, and more. This helps to improve the performance and reliability of your website or application by distributing the workload evenly.

Setting Up Upstream Directive

To set up an upstream directive in Nginx, you need to follow these steps:

Step 1: Define the Upstream Block

Open your Nginx configuration file, usually located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf. Inside the http block, add the following code to define the upstream block:

http {
  upstream backend {
    server backend1.example.com;
    server backend2.example.com;
    server backend3.example.com;
  }
}

In this example, we have defined an upstream block named “backend” and listed three backend servers. You can replace the server names with the actual IP addresses or domain names of your backend servers.

Step 2: Configure the Proxy Pass

Next, you need to configure the proxy pass to forward the incoming requests to the backend servers. Inside the server block, add the following code:

server {
  listen 80;
  server_name example.com;

  location / {
    proxy_pass http://backend;
  }
}

In this example, we have configured Nginx to listen on port 80 for requests to the domain “example.com”. The proxy_pass directive is set to forward the requests to the upstream block named “backend”.

Step 3: Test and Reload Nginx

Save the configuration file and test it for syntax errors by running the following command:

sudo nginx -t

If there are no errors, reload Nginx to apply the changes:

sudo systemctl reload nginx

Your Nginx server is now set up with an upstream directive, and incoming requests will be distributed among the backend servers defined in the upstream block.

Summary

Nginx’s upstream directive is a powerful feature that allows you to distribute incoming requests to multiple backend servers, improving the performance and reliability of your website or application. By following the steps outlined in this article, you can easily set up an upstream directive in Nginx.

If you are looking for a reliable VPS hosting provider to host your Nginx server, consider Server.HK. With their top-notch VPS solutions and excellent customer support, you can ensure the smooth operation of your website or application.

Recent Posts

  • CentOS Stream Explained: Key Differences from CentOS Linux
  • How to Configure FirewallD in CentOS Stream: From Essential to Production-Grade
  • Installing Docker on CentOS: A Practical Setup Guide (CentOS Stream 9/10 – 2026)
  • How to Secure a CentOS Server: 15 Essential Hardening Techniques (CentOS Stream 9/10 – 2026)
  • CentOS End of Life (EOL): What It Means and Migration Options in 2026

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot