服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - Nginx - Nginx实现Nacos反向代理的项目实践

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

2022-08-03 17:42烟火缠过客 Nginx

在日常的web网站部署中,经常会用到nginx反向代理,本文主要介绍了Nginx实现Nacos反向代理的项目实践,Nginx实现Nacos反向代理的项目实践

1.win10安装Nginx

nginx下载地址

nginx: download

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

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

启动

?
1
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文件,使用外置数据源

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
### 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,添加节点配置

?
1
2
3
#2022-03-23T10:56:12.825
localhost:8849
localhost:8850

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

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

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

?
1
startup.cmd

6.配置nginx.conf

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#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

?
1
start nginx.exe

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

http://localhost:8847/nacos

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

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

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

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

 到此这篇关于Nginx实现Nacos反向代理的项目实践的文章就介绍到这了,更多相关Nginx Nacos反向代理内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/LuckFairyLuckBaby/article/details/123682656

延伸 · 阅读

精彩推荐