nginx实现负载均衡,也是反向代理的过程
upstream panel_gateway {
server 172.16.2.173:27002;
server 172.16.2.174:27002;
}
server {
listen 10088 ssl;
server_name smartpanel.andshi.cn;
ssl_certificate cert/1794716__andshi.cn.pem;
ssl_certificate_key cert/1794716__andshi.cn.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:1m;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!ADH:!MD5:!RC4;
ssl_prefer_server_ciphers on;
client_max_body_size 100m;
location / {
root /data/smartpanel-web/dist;
index index.html;
if ($request_filename ~ .*\.(js|css|png)$)
{
add_header Cache-Control public;
}
}
location /root/ {
proxy_pass http://panel_gateway/;
}
反向代理:请求的来源也就是客户端是明确的,但是请求具体由哪台服务器处理的并不明确了
正向代理
server {
listen 80;
server_name xiaohost.com www.xiaohost.com;
charset utf-8;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://192.168.1.2:80;
}
}
正向代理:客户端非常明确要访问的服务器地址;服务器只清楚请求来自哪个代理服务器,而不清楚来自哪个具体的客户端;正向代理模式屏蔽或者隐藏了真实客户端信息。