Nginx反向代理
Nginx作为近年来较火的反向代理服务器,安装在目的主机端,主要用于转发客户机请求,后台有多个http服务器提供服务,nginx的
功能就是把请求转发给后面的服务器,决定哪台目标主机来处理当前请求。
1)模拟n个http服务器作为目标主机
用作测试,简单的使用2个tomcat实例模拟两台http服务器,分别将tomcat的端口改为8081和8082
2)配置IP域名
192.168.72.49 8081.max.com
192.168.72.49 8082.max.com
3)配置nginx.conf
upstream tomcatserver1 {
server 192.168.72.49:8081;
}
upstream tomcatserver2 {
server 192.168.72.49:8082;
}
server {
listen 80;
server_name 8081.max.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver1;
index index.html index.htm;
}
}
server {
listen 80;
server_name 8082.max.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver2;
index index.html index.htm;
}
}
4)流程:
①浏览器访问8081.max.com,通过本地host文件域名解析,找到192.168.72.49服务器(安装nginx)
②nginx反向代理接受客户机请求,找到server_name为8081.max.com的server节点,根据proxy_pass对应的http路径,将请求
转发到upstream tomcatserver1上,即端口号为8081的tomcat服务器。
Nginx反向代理
最新推荐文章于 2025-05-26 15:02:09 发布
1688

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



