Nginx實現(xiàn)Nacos反向代理的項目實踐
1.win10安裝Nginx
nginx下載地址
下載后解壓,進(jìn)入bin目錄,根據(jù)你的系統(tǒng)執(zhí)行相應(yīng)的命令
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.復(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é)點配置
#2022-03-23T10:56:12.825 localhost:8849 localhost:8850
4.另外幾臺也照這個配置修改,注意端口號的修改
創(chuàng)建mysql數(shù)據(jù)庫,sql文件位置:conf\nacosmysql.sql
5.分別啟動三臺nacos,啟動命令為進(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)聽的是8847端口,所以我們登錄nacos直接使用nginx進(jìn)行代理
http://localhost:8847/nacos
我們可以看到當(dāng)你刷新的時候,分配到的是不同的服務(wù)器上



到此這篇關(guān)于Nginx實現(xiàn)Nacos反向代理的項目實踐的文章就介紹到這了,更多相關(guān)Nginx Nacos反向代理內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx靜態(tài)文件響應(yīng)POST請求 提示405錯誤的解決方法
Apache、IIS、nginx等絕大多數(shù)web服務(wù)器,都不允許靜態(tài)文件響應(yīng)POST請求,否則會返回“HTTP/1.1 405 Method not allowed”錯誤2013-04-04
nginx服務(wù)器實現(xiàn)上傳下載文件的實例代碼
這篇文章主要介紹了nginx服務(wù)器實現(xiàn)上傳下載文件的實例代碼,本文通過代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02
Nginx 代理轉(zhuǎn)發(fā)阿里云OSS上傳的實現(xiàn)代碼
這篇文章主要介紹了Nginx 代理轉(zhuǎn)發(fā)阿里云OSS上傳的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
nginx could not build the server_names_hash 解決方法
服務(wù)器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。2011-03-03

