Nginx实现Nacos反向代理的项目实践

作者:烟火缠过客 时间:2021-05-27 15:52:34 

1.win10安装Nginx

nginx下载地址

nginx: download

下载后解压,进入bin目录,根据你的系统执行相应的命令

1.1 windows系统启动和停止的命令

启动

start nginx.exe

终止

nginx.exe -s stop //停止nginx

nginx.exe -s reload //重新加载nginx

nginx.exe -s quit //退出nginx

2.win10安装nacos

nacos官网网址

Nacos 快速开始

2.1 搭建三台nacos步骤

1.复制三份解压后的nacos文件包分别命名如下

  • nacos8848

  • nacos8849

  • nacos8850

Nginx实现Nacos反向代理的项目实践

 2.以nacos8848为例,进入该目录,进入conf目录修改application.properties文件,使用外置数据源

### Default web server port:
server.port=8848

#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false

### Specify local server's IP:
# nacos.inetutils.ip-address=
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=root

3.将conf/cluster.conf.example改为cluster.conf,添加节点配置

#2022-03-23T10:56:12.825
localhost:8849
localhost:8850

4.另外几台也照这个配置修改,注意端口号的修改

创建mysql数据库,sql文件位置:conf\nacos­mysql.sql

5.分别启动三台nacos,启动命令为进入到bin目录,cmd执行startup.cmd

startup.cmd

6.配置nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
   worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
   #                  '$status $body_bytes_sent "$http_referer" '
   #                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
   #tcp_nopush     on;

#keepalive_timeout  0;
   keepalive_timeout  65;

#gzip  on;
upstream nacoscluster {
server localhost:8848;
server localhost:8849;
server localhost:8850;
}

server {
       listen       8847;
       server_name  localhost;

location /nacos/ {
           proxy_pass http://nacoscluster/nacos/;
       }

location = /50x.html {
           root   html;
       }
       error_page   500 502 503 504  /50x.html;
   }

server {
       listen       80;
       server_name  localhost;

location / {
           root   html;
           index  index.html index.htm;
       }

error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }

}

7.执行nginx

start nginx.exe

我们监听的是8847端口,所以我们登录nacos直接使用nginx进行代理

http://localhost:8847/nacos

我们可以看到当你刷新的时候,分配到的是不同的服务器上

Nginx实现Nacos反向代理的项目实践

Nginx实现Nacos反向代理的项目实践

Nginx实现Nacos反向代理的项目实践

来源:https://blog.csdn.net/LuckFairyLuckBaby/article/details/123682656

标签:Nginx,Nacos,反向代理
0
投稿

猜你喜欢

  • 投放google Adsense的三点心得

    2009-01-08 11:11:00
  • 建站经验之规划网站内容

    2007-09-11 13:17:00
  • 在Linux系统下配置WU-FTP服务器

    2008-09-26 17:24:00
  • 改变草根站长的命运

    2007-09-28 11:44:00
  • Linux使用ssh公钥实现免密码登录实例

    2023-08-16 21:35:02
  • LVS+Keepalived构建高可用负载均衡配置方法(配置篇)

    2023-08-14 21:04:57
  • Web服务器日志工具点评

    2009-07-23 12:34:00
  • 网站推广系列导读:目标群体、载体和策略

    2009-02-14 21:52:00
  • 建站实战:母婴网站后起之秀乐儿网成长路

    2009-05-05 18:15:00
  • Photoshop官方提供2G可外链的免费相册

    2009-07-30 13:03:00
  • 开放重定向:您的网站有没有被恶意地利用

    2009-02-18 17:04:00
  • 研究Linux下Firewall防火墙的配置

    2009-08-29 10:12:00
  • 详解Linux查看实时网卡流量的几种方式

    2023-08-22 02:07:13
  • Exchange 2007 安装全过程

    2010-02-22 19:24:00
  • 开发者感兴趣的IE8 beta1的七大改进

    2008-03-09 15:13:00
  • 详细:网站被降权的原因分析以及解决办法

    2008-12-16 10:02:00
  • Linux查看PCIe版本及速率的方法

    2023-08-31 04:14:56
  • apache日志文件详解和实用分析命令

    2021-12-11 22:01:49
  • 把域名转移到Godaddy图文教程

    2010-04-07 12:30:00
  • 个人站长必备的100条广告版块版规用语

    2009-01-06 00:51:00
  • asp之家 网站运营 m.aspxhome.com