Nginx實(shí)現(xiàn)Nacos反向代理的項(xiàng)目實(shí)踐
1.win10安裝Nginx
nginx下載地址
下載后解壓,進(jìn)入bin目錄,根據(jù)你的系統(tǒng)執(zhí)行相應(yīng)的命令
1.1 windows系統(tǒng)啟動(dòng)和停止的命令
啟動(dòng)
start nginx.exe
終止
nginx.exe -s stop //停止nginx
nginx.exe -s reload //重新加載nginx
nginx.exe -s quit //退出nginx
2.win10安裝nacos
nacos官網(wǎng)網(wǎng)址
2.1 搭建三臺(tái)nacos步驟
1.復(fù)制三份解壓后的nacos文件包分別命名如下
- nacos8848
- nacos8849
- nacos8850

2.以nacos8848為例,進(jìn)入該目錄,進(jìn)入conf目錄修改application.properties文件,使用外置數(shù)據(jù)源
### 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,添加節(jié)點(diǎn)配置
#2022-03-23T10:56:12.825 localhost:8849 localhost:8850
4.另外幾臺(tái)也照這個(gè)配置修改,注意端口號(hào)的修改
創(chuàng)建mysql數(shù)據(jù)庫(kù),sql文件位置:conf\nacosmysql.sql
5.分別啟動(dòng)三臺(tái)nacos,啟動(dòng)命令為進(jìn)入到bin目錄,cmd執(zhí)行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.執(zhí)行nginx
start nginx.exe
我們監(jiān)聽(tīng)的是8847端口,所以我們登錄nacos直接使用nginx進(jìn)行代理
http://localhost:8847/nacos
我們可以看到當(dāng)你刷新的時(shí)候,分配到的是不同的服務(wù)器上



到此這篇關(guān)于Nginx實(shí)現(xiàn)Nacos反向代理的項(xiàng)目實(shí)踐的文章就介紹到這了,更多相關(guān)Nginx Nacos反向代理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx根據(jù)不同瀏覽器語(yǔ)言配置頁(yè)面跳轉(zhuǎn)的方法
這篇文章主要介紹了Nginx根據(jù)不同瀏覽器語(yǔ)言配置頁(yè)面跳轉(zhuǎn)的方法,包括一個(gè)簡(jiǎn)體繁體的基本判斷方法及實(shí)際根據(jù)中英文跳轉(zhuǎn)的例子,需要的朋友可以參考下2016-04-04
Linux下Nginx負(fù)載均衡多個(gè)tomcat配置的方法步驟
這篇文章主要介紹了Linux下Nginx負(fù)載均衡多個(gè)tomcat配置的方法步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-04-04
Nginx下修改WordPress固定鏈接導(dǎo)致無(wú)法訪問(wèn)的問(wèn)題解決
這篇文章主要介紹了Nginx下修改WordPress固定鏈接導(dǎo)致無(wú)法訪問(wèn)的問(wèn)題解決,同時(shí)作者也給出了官方關(guān)于修改固定鏈接的方法,需要的朋友可以參考下2015-07-07
Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn)
本文主要介紹了Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
Nginx實(shí)現(xiàn)自簽名SSL證書生成與配置實(shí)現(xiàn)
本文主要介紹了Nginx實(shí)現(xiàn)自簽名SSL證書生成與配置實(shí)現(xiàn),文章將詳細(xì)介紹生成自簽名SSL證書的步驟,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09
Keepalived+Nginx+Tomcat 實(shí)現(xiàn)高可用Web集群的示例代碼
這篇文章主要介紹了Keepalived+Nginx+Tomcat 實(shí)現(xiàn)高可用Web集群的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09

