nginx tomcat负载均衡配置
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
步驟一:到nginx官網(wǎng)下載nginx,我是下載的最新版本nginx/Windows-1.9.10,下載鏈接http://nginx.org/en/download.html。
步驟二:將下載下來的文件解壓,打開nginx-1.9.10 ?conf目錄,修改nginx.conf。找到#gzip ?on;這句代碼
在代碼下面配置要代理的tomcat
upstream localhost { ? ?
server localhost:8081 weight=1;
server localhost:8082 weight=2; ?
? ? }?
? ? server {
? ? ? ? listen ? ? ? 9000;????//默認(rèn)端口是80被占用了,所以改成9000了
? ? ? ? server_name ?localhost;
? ? ? ? #charset koi8-r;
? ? ? ? #access_log ?logs/host.access.log ?main;
? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
proxy_connect_timeout ? 3; ?
proxy_send_timeout ? ? ?30; ?
proxy_read_timeout ? ? ?30;
proxy_pass http://localhost; ?
? ? ? ? }
在location配置里面加上紅色字體代碼;
配置好之后到nginx-1.9.10目錄下shift+鼠標(biāo)右鍵,在此處打開命令窗口(window系統(tǒng)),會看到彈出一個dos命令窗口,
通過命令nginx -t可以看下測試是否成功;
nginx命令:
nginx -t;????//查看測試是否成功
start nginx;????//啟動nginx
nginx -s stop;????//停止nginx
步驟三:準(zhǔn)備2個tomcat,修改里面的端口號,一個是8081,另一個是8082(就是上面要代理的tomcat的端口號),修改2個tomcat ?webapps目錄下index.jsp,在兩個頁面上加上標(biāo)識,方便等下測試看是訪問的哪個tomcat;
步驟四:啟動nginx和tomcat,然后在瀏覽器訪問localhost:9000(這個端口號是上面nginx的端口號),可以看到瀏覽器有時候訪問的是8081端口號的tomcat,有時候訪問的是8082端口號的tomcat。如果是這樣,就表示ok了。
如有錯誤,請大神指點(diǎn)!
轉(zhuǎn)載于:https://my.oschina.net/u/2001417/blog/610785
總結(jié)
以上是生活随笔為你收集整理的nginx tomcat负载均衡配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React.js 2016 最佳实践
- 下一篇: filter(HTML)滤镜用法