我有 3 个端口正在加载不同的内容,我想从端口 8080 对它们进行负载平衡。我是 nginx 新手,我觉得在 nginx 上提供内容方面,我有一些基本的东西我不太理解。我的 3 个端口独立工作,但没有负载平衡。我该如何编辑配置以在这 3 个端口之间实现负载平衡?
upstream backend {
server localhost:8081;
server localhost:8082;
server localhost:8083;
}
server {
listen 8080;
listen [::]:8080;
server_name _;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
# Default server configuration
#
server {
listen 8081 default_server;
listen [::]:8081 default_server;
root /var/www/n81;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
server {
listen 8082 default_server;
listen [::]:8082 default_server;
root /var/www/n82;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
server {
listen 8083 default_server;
listen [::]:8083 default_server;
root /var/www/n83;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}