nginx 配置反向代理和负载均衡
Posted -saligia-
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 配置反向代理和负载均衡相关的知识,希望对你有一定的参考价值。
nginx的配置文件:
nginx安装目录/conf/nginx.conf
重新加载配置文件
./nginx -s reload
配置虚拟主机
一个server就是一台虚拟主机
server {
listen 80;//监听端口
server_name localhost;//域名
location / {
root html;
index index.html index.htm;
}
}
反向代理与负载均衡
upstream tomcat {
server ip1:端口号1 weight=2;
server ip2:端口号2 weight=2;//权重
}
server {
listen 80;//监听端口
server_name www.test.com;//域名
location / {
proxy_pass http://tomcat2;
index index.html index.htm;
}
}
以上是关于nginx 配置反向代理和负载均衡的主要内容,如果未能解决你的问题,请参考以下文章
nginx做反向代理负载均衡 Java怎么获取后端服务器获取用户IP
Nginx入门:通俗理解反向代理和负载均衡,简单配置Nginx