Nginx 反向代理的方案

3.1 常规部署方案

 

3.2 Nginx反向代理 

3.2.1 web01和web02安装nginx 

web01配置
[root@linux-node4 ~]# yum -y install nginx 
[root@linux-node4 ~]# echo web01 > /usr/share/nginx/html/index.html
web02配置
[root@linux-node4 ~]# yum -y install nginx 
[root@linux-node4 ~]# echo web01 > /usr/share/nginx/html/index.html
测试nginx服务 
http://192.168.56.62/ # web01 
http://192.168.56.63/ # web02

3.2.2 nginx反向代理配置 

安装nginx服务器 
[root@linux-node4 ~]# yum -y install nginx
配置反向代理 
stream {
    log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent'; 
    access_log /var/log/nginx/django-access.log main;
    upstream django-apiserver {
             server 192.168.56.62:80; 
            server 192.168.56.63:80; 
        }
    server { 
        listen 88; 
        proxy_pass django-apiserver; 
    } 
}                
View Code
完整配置如下 (看一下即可,都是nginx默认配置) 
[root@lb-master ~]# cat /etc/nginx/nginx.conf 

user     nginx; 

worker_processes     1; 

error_log     /var/log/nginx/error.log warn; 

pid     /var/run/nginx.pid; 

events {

​            worker_connections 1024; 

}

stream {

​            log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent'; 

​            access_log /var/log/nginx/django-access.log main; 

​            upstream django-apiserver { 

​                                            server 192.168.56.62:80; 

​                                            server 192.168.56.63:80; 

​            } 

​            server { 

​                        listen 80; 

​                        proxy_pass django-apiserver; 

​            }     

}

http {

​            include                 /etc/nginx/mime.types; 

​            default_type     application/octet-stream; 

​            log_format     main     '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'; 

​            access_log         /var/log/nginx/access.log     main; 

​            sendfile                 on; 

​           #tcp_nopush         on; 

​            keepalive_timeout     65; 

​            #gzip on; 

​            include /etc/nginx/conf.d/*.conf; 

} 
测试反向代理可用性
做最野的狼
原文地址:https://www.cnblogs.com/shanjiaaa/p/14281336.html