使用nginx的upstream模块进行负载
第一、不想要加访问路径配置
首先配置的时候需要把nacos配置的访问路径删除
vim application.properties
重新启动nacos 三个节点都配置一样的
vim /etc/nginx/conf.d/default.conf 然后编写nginx的配置文件
Nginx服务器ip 192.168.11.154
upstream nacos {
server 192.168.11.139:8848;
server 192.168.11.141:8848;
server 192.168.11.142:8848;
}
server {
listen 8081;
server_name localhost; #ip 或者域名
location / {
proxy_pass http://nacos;
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;
}
systemctl restart nginx 配置完重启nginx
访问192.168.11.154:8081
第二需要加访问路径的
vim /etc/nginx/conf.d/default.conf 然后编写nginx的配置文件
Nginx服务器ip 192.168.11.154
upstream nacos {
server 192.168.11.139:8848;
server 192.168.11.141:8848;
server 192.168.11.142:8848;
}
server {
listen 8081;
server_name localhost; #ip 或者域名
location /nacos {
proxy_pass http://nacos;
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;
}
systemctl restart nginx 配置完重启nginx
访问192.168.11.154:8081/nacos