Nginx實現(xiàn)Nacos反向代理的項目實踐
1.win10安裝Nginx
nginx下載地址
下載后解壓,進入bin目錄,根據(jù)你的系統(tǒng)執(zhí)行相應的命令
1.1 windows系統(tǒ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 搭建三臺nacos步驟
1.復制三份解壓后的nacos文件包分別命名如下
- nacos8848
- nacos8849
- nacos8850
2.以nacos8848為例,進入該目錄,進入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é)點配置
#2022-03-23T10:56:12.825 localhost:8849 localhost:8850
4.另外幾臺也照這個配置修改,注意端口號的修改
創(chuàng)建mysql數(shù)據(jù)庫,sql文件位置:conf\nacosmysql.sql
5.分別啟動三臺nacos,啟動命令為進入到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)聽的是8847端口,所以我們登錄nacos直接使用nginx進行代理
http://localhost:8847/nacos
我們可以看到當你刷新的時候,分配到的是不同的服務器上
到此這篇關于Nginx實現(xiàn)Nacos反向代理的項目實踐的文章就介紹到這了,更多相關Nginx Nacos反向代理內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Nginx根據(jù)不同瀏覽器語言配置頁面跳轉(zhuǎn)的方法
這篇文章主要介紹了Nginx根據(jù)不同瀏覽器語言配置頁面跳轉(zhuǎn)的方法,包括一個簡體繁體的基本判斷方法及實際根據(jù)中英文跳轉(zhuǎn)的例子,需要的朋友可以參考下2016-04-04Linux下Nginx負載均衡多個tomcat配置的方法步驟
這篇文章主要介紹了Linux下Nginx負載均衡多個tomcat配置的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04Nginx下修改WordPress固定鏈接導致無法訪問的問題解決
這篇文章主要介紹了Nginx下修改WordPress固定鏈接導致無法訪問的問題解決,同時作者也給出了官方關于修改固定鏈接的方法,需要的朋友可以參考下2015-07-07Nginx實現(xiàn)自簽名SSL證書生成與配置實現(xiàn)
本文主要介紹了Nginx實現(xiàn)自簽名SSL證書生成與配置實現(xiàn),文章將詳細介紹生成自簽名SSL證書的步驟,具有一定的參考價值,感興趣的可以了解一下2023-09-09Keepalived+Nginx+Tomcat 實現(xiàn)高可用Web集群的示例代碼
這篇文章主要介紹了Keepalived+Nginx+Tomcat 實現(xiàn)高可用Web集群的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09