七层负载:
[root@www ~]# cat /etc/nginx/conf.d/test.conf
upstream phpserver {
server192.168.2.3;
server192.168.2.4;
}
upstream htmlserver {
server192.168.2.1;
server192.168.2.2;
}
[root@www ~]# vim /etc/nginx/nginx.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm;
if ($request_uri ~*\.html$){
proxy_pass http://htmlserver;
}
if ($request_uri~* \.php$){
proxy_pass http://phpserver;
}
}
四层负载:
[root@linux-node1 conf]# vim nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
stream { #类似于7层的http段
upstream ssh_proxy {
hash $remote_addr consistent;
server 192.168.56.2:22;
server 192.168.56.3:22;
}
server {
listen 2222;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass ssh_proxy;
}
}
转载请注明:SuperIT » nginx四层和七层负载均衡的区别