1.反向代理多个虚拟主机节点服务器
环境
| 反向代理服务器 | 192.168.76.4 |
| web1 |
192.168.76.5 |
| web2 | 192.168.76.6 |
先给web1和web2安装nginx web基本配置
web1: echo "`hostname -I `www" >/usr/share/nginx/html/index.html
web2: echo "`hostname -I `bbs" >/usr/share/nginx/html/index.html
然后在反向代理服务器中写好dns解析。
最后在nginx配置文件或者子配置文件夹中填写以下内容。
upstream wwwServerPools {
server 192.168.76.3:80 weight=1;
server 192.168.76.5:80 weight=1;
}
server {
listen 80;
server_name yunjisuan.com;
location / {
proxy_pass http://wwwServerPools;
proxy_set_header Host $host;
#proxy_set_header X-Forwarded-For $remote_addr;
}
}
server {
listen 80;
server_name wangluoanquan.com;
location / {
proxy_pass http://wwwServerPools;
proxy_set_header Host $host;
#proxy_set_header X-Forwarded-For $remote_addr;
}
}
2.经过反向代理后的节点服务器记录用户ip
如果web服务器是nginx部署的话,直接在反向代理服务器中nginx配置文件中添加

在web服务器的日志文件中就可以看到ip

要是web服务器是用apache部署的话,修改vim /etc/httpd/conf/httpd.conf

在%h后添加即可
本文介绍了如何通过Nginx配置反向代理,将来自不同域名的请求分发到web1和web2服务器,并记录用户IP。涉及DNS解析、upstream池设置及服务器名称匹配。
1087

被折叠的 条评论
为什么被折叠?



