Nginx+Tomcat

#環境介紹
10.0.0.21    nginx
10.0.0.22	 tomcat(兩個節點)


#1.安裝nginx(10.0.0.21)
yum或編譯安裝方式均可,可參考第九單元。

yum -y install gcc gcc-c++ pcre-devel openssl-devel openssl wget
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx
make
make install

/usr/local/nginx/sbin/nginx


#2.部署tomcat(兩個節點)(10.0.0.22)
參考第十二單元。



#3.通過Nginx和Tomcat結合
修改Nignx配置文件
vim /usr/local/nginx/conf/nginx.conf

#配置反代或負載均衡的池子
在HTTP模塊中添加:
upstream tomcat {     #定義服務器組tomcat
    server 10.0.0.22:8080;    #定義後Tomcat端服務器
    server 10.0.0.22:18080;
}


在server模塊中添加:
location ~ \.jsp$ {   #URL正則匹配,匹配jsp結尾的所有URL
	proxy_pass   http://tomcat;   #proxy_pass反向代理參數,將匹配到的請求反向代理到tomcat服務器組!
}


啓動nginx並測試

發佈了40 篇原創文章 · 獲贊 14 · 訪問量 1388
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章