Nginx负载均衡:
格式:
upstream 别名 { #别名一般要有意义,能看出是做什么的
server ip:端口; #要实现负载的服务器的ip、端口号
}
例:
upstream a {
server 192.168.1.7:8080;
}
upstream b {
server 192.168.1.101:8080;
server 192.168.1.102:8080;
server 192.168.1.103:8080;
}
Nginx反向代理:
格式:
server {
listen 监听端口;
server_name localhost;
proxy_set_header Host $host:$server_port;
location / {
proxy_pass http://负载设置的别名(或ip); #反向代理:有设置负载均衡时,使用负载均衡定义的别名;没有负载均衡时,直接使用要代理的ip、端口号
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
例:
server {
listen 8078;
server_name localhost;
proxy_set_header Host $host:$server_port;
location / {
proxy_pass http://a;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8079;
server_name localhost;
proxy_set_header Host $host:$server_port;
location / {
proxy_pass http://b);
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}