Mac下Tomcat+Ngnix負(fù)載均衡

下載 不同版本的 Tomcat

https://tomcat.apache.org/download-90.cgi

打開各自server.conf修改tomcat端口號(hào),主要為了一臺(tái)電腦下運(yùn)行兩個(gè)tomcat防止端口沖突

第一個(gè)tomcat:修改port由8080改為18080,第三個(gè)端口號(hào)不必與前兩個(gè)一致

<Server port="8005" shutdown="SHUTDOWN">
    <Connector port="18080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" /> 
    <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />
</Service>

第二個(gè)tomcat: 修改port由8080改為28080,第三個(gè)防止與前一個(gè)tomcat端口沖突

<Server port="18005" shutdown="SHUTDOWN">
    <Connector port="28080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />     
    <Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />
</Service>

2.各自啟動(dòng)tomcat,進(jìn)入index.jsp頁面

進(jìn)入tomcat bin目錄,命令 ./startup.sh 啟動(dòng)tomcat

輸入地址:

http://localhost:18080/index.jsp

http://localhost:28080/index.jsp

命令 ./shutdown.sh 關(guān)閉tomcat

關(guān)于LINUX權(quán)限-bash: ./startup.sh: Permission denied

<script type="text/javascript"></script><script type="text/javascript"></script>

在執(zhí)行./startup.sh,或者./shutdown.sh的時(shí)候,爆出了Permission denied,

其實(shí)很簡單,就是今天在執(zhí)行tomcat的時(shí)候,用戶沒有權(quán)限,而導(dǎo)致無法執(zhí)行,

用命令chmod 修改一下bin目錄下的.sh權(quán)限就可以了

如chmod u+x *.sh

在此執(zhí)行,OK了。

3.在終端上通過homebrew安裝nginx

brew 查看是否安裝brew

brew search nginx 查詢是否有nginx

brew install nginx 安裝nginx

此處會(huì)彈出 Updating Homebrew...耐心等待幾分鐘

安裝完畢 輸入nginx -v 查詢版本號(hào)安裝是否成功

地址欄輸入 http://localhost:8080 安裝成功會(huì)提示

Welcome to nginx!

之前已安裝nginx的情況

啟動(dòng)Nginx:

啟動(dòng)代碼格式:nginx安裝目錄地址 -c nginx配置文件地址

例如: /usr/local/bin/nginx -c /usr/local/etc/nginx/nginx.conf

4.找到nginx配置目錄

/usr/local/etc/nginx

修改nginx.conf

gzip on;

upstream [zmy.com](http://zmy.com){

server 127.0.0.1:18080 weight=1;

server 127.0.0.1:28080 weight=2;

}

  server{

    listen       8080;

    server_name  localhost;

    location / {

        proxy_pass [http://zmy.com](http://zmy.com);

        proxy_redirect default;

    }

}

vim nginx.conf 修改

保存修改,重啟nginx,在 nginx根目錄下輸入命令:

sudo nginx -s reload

重啟完畢

5.地址欄輸入

http://localhost:8080/index.jsp

刷新看看nginx訪問到哪個(gè)版本的tomcat上

注:

啟動(dòng)nginx

sudo nginx

修改 nginx.conf 后,重載配置文件

sudo nginx -s reload

停止 nginx 服務(wù)器

sudo nginx -s stop

參考: https://blog.csdn.net/lanqibaoer/article/details/72853056

lunix修改內(nèi)存: http://www.gwork.cn/?post=6

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容