我正在使用nginx监听端口8080并在端口8081,8081,8083和8084上的四个龙卷风实例上使用nginx.conf进行平衡。如何强制nginx监听另一个端口8090并在端口8091,8092,8093和8094上进行平衡? 在[808 *]上运行的龙卷风实例与[809 *]
不同8080 balance on [8081, 8082, 8083, 8084]
8090 balance on [8091, 8092, 8093, 8094]
有nginx.conf
worker_processes 16;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
#master_process off;
daemon off;
events {
worker_connections 1024;
use epoll;
}
http {
charset utf-8;
# Enumerate all the Tornado servers here
upstream frontends {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
server 127.0.0.1:8084;
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
proxy_buffering off;
proxy_buffers 4 512k;
proxy_buffer_size 512k;
access_log /var/log/nginx/access.log;
#keepalive_timeout 65;
#proxy_read_timeout 200;
keepalive_timeout 600;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/html text/plain text/css application/javascript application/x-javascript text/javascript text/xml application/xml;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream off;
server {
listen 8080;
server_name localhost;
location /
{
access_log off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Allow file uploads
client_max_body_size 50M;
location ^~ /static/ {
root /home/server/;
if ($query_string) {
expires max;
}
}
}
}
答案 0 :(得分:2)
您需要两个upstream
和两个server
块。像这样的东西(其他选项像以前一样填写):
http {
upstream eighties {
server http://127.0.0.1:8081;
server http://127.0.0.1:8082;
}
upstream nineties {
server http://127.0.0.1:8091;
server http://127.0.0.1:8092;
}
server {
listen 8080;
location / {
proxy_pass http://eighties;
}
}
server {
listen 8090;
location / {
proxy_pass http://nineties;
}
}
}