第一种方式
worker_processes 2;
#error_log /var/log/nginx/error.log;
#pid /var/run/nginx.pid;
events {
worker_connections 10240;
use epoll;
}
http {
charset utf-8;
#map $zone $up_stream {
# ^~test1 frontends_0769;
# ^~test frontends_0734;
#default frontends_0769;
#}
# Enumerate all the Tornado servers here
upstream frontends_immsg {
server 127.0.0.1:8081;
}
upstream frontends_idman {
server 127.0.0.1:8082;
}
upstream frontends_firm {
server 127.0.0.1:8080;
}
include mime.types;
default_type application/octet-stream;
#access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
# 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 error;
server {
listen 80;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends_idman;
}
location /study {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends_idman;
}
location /immsg {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends_immsg;
}
location /firm {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends_firm;
}
}
}
第二种方式使用map
worker_processes 2;
#error_log /var/log/nginx/error.log;
#pid /var/run/nginx.pid;
events {
worker_connections 10240;
use epoll;
}
http {
charset utf-8;
map $zone $up_stream {
^~123 frontends_123;
^~456 frontends_456;
^~789 frontends_789;
default frontends_123;
}
# Enumerate all the Tornado servers here
upstream frontends_123 {
server 127.0.0.1:8080;
}
upstream frontends_456 {
server 127.0.0.1:8081;
}
upstream frontends_789 {
server 127.0.0.1:8082;
}
include mime.types;
default_type application/octet-stream;
#access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
# 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 error;
server {
listen 80;
server_name 120.24.226.118;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
#proxy_pass http://frontends_456;
if ( $request_uri ~ ^/(\d+)/(.*)$ ) {
set $zone $1;
proxy_pass http://$up_stream;
}
} }
}
第二种方式是摘与网上的 我搔搔改了下 但实际应用有待加强