nginx鍩轰簬HTTP瀹炵幇璐熻浇鍧囪 tomcat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx鍩轰簬HTTP瀹炵幇璐熻浇鍧囪 tomcat相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/rtu' title='rtu'>rtu   tle   鍩轰簬   閰嶇疆   art   mkdir   鍐呭   odi   weight   

閰嶇疆鐜锛?/strong>

鏈€灏戜袱鍙皌omcat鏈嶅姟鍣ㄥ拰涓€鍙皀ginx鏈嶅姟鍣?/strong>

鍏堟潵閰嶇疆tomcat鏈嶅姟鍣?锛屽湪瀹夎浜唗omcat鏈嶅姟鐨勫熀纭€涓?/strong>

1.棣栧厛鍦ㄦ牴鐩綍涓嬪缓绔嬩竴涓獁eb鐩綍锛屽苟鍦ㄩ噷杈瑰缓绔嬩竴涓獁ebapp鐩綍锛岀敤浜庡瓨鏀剧綉绔欐枃浠?/strong>銆?/p>

mkdir -pv /web/webapp

2.鍦╳ebapp鐩綍涓嬪缓绔嬩竴涓猧ndex.jsp鐨勬祴璇曢〉闈?/strong>

vim /web/webapp/index.jsp

 娣诲姞鍐呭锛?/p>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<html>

銆€銆€<head>

銆€銆€銆€銆€<title>JSP test page</title>

銆€銆€</head>

銆€銆€<body>

銆€銆€銆€銆€<% out.println"Welcome to test site,http://www.test1.com";%>

銆€銆€</body>

</html>

3.淇敼tomcat鐨剆erver.xml鏂囦欢

瀹氫箟涓€涓櫄鎷熶富鏈猴紝骞跺皢缃戦〉鏂囦欢璺緞鎸囧悜宸茬粡寤虹珛鐨?web/webapp锛屽湪host娈靛鍔燾ontext娈?/p>

cd /usr/local/tomcat8/conf/

cp server.xml server.xml.bak

vim server.xml

150琛屾坊鍔犲唴瀹癸細

<Context docBass="/web/webapp" path="" reloadable="flase">

</Context>

4.閲嶅惎鏈嶅姟

/usr/local/tomcat8/bin/shutdown.sh

/usr/local/tomcat8/bin/startup.sh

5.杩涘叆缃戦〉杩涜娴嬭瘯

IP鍦板潃鍚庤窡绔彛鍙凤細8080

6.鏌ョ湅鏂囦欢鏃ュ織

ls /usr/local/tomcat/logs/

tomcat鏈嶅姟鍣?锛屽悓1閰嶇疆涓€鏍凤紝鍙湁鍦ㄤ富閰嶇疆鏂囦欢涓殑缃戦〉涓嶅悓

===========================================================

 

鎺ヤ笅鏉ュ湪瀹夎浜唍ginx鏈嶅姟鐨勫熀纭€涓婇厤缃畁ginx鏈嶅姟鍣?/strong>

1.淇敼閰嶇疆鏂囦欢

vim /usr/local/nginx/conf/nginx.conf

娣诲姞鍐呭锛?/strong>

鍦╧eepalive timeout 65涓?/strong>

upstream tomcat_server銆€銆€銆€銆€#瀹氫箟涓€涓祫婧愭睜锛岀敤鏉ュ瓨鏀惧涓皟搴︽湇鍔″櫒

server 192.168.200.111:8080 weight=1;銆€銆€#weight浠h〃鏉冮噸锛岃兘鍔涜秺澶э紝鏉冮噸瓒婂ぇ

server 192.168.200.112:8080 weight=1;銆€銆€

**璐熻浇鍧囪 璋冨害鐘舵€侊細

down  琛ㄧず褰撳墠server涓嶅弬涓庤礋杞?/strong>

backup  棰勭暀鐨勫鐢ㄦ満鍣紝鍘嬪姏灏?/strong>

max_fails  鍏佽璇锋眰澶辫触鐨勬鏁?/strong>

fail_timeout  璇锋眰澶辫触瓒呮椂鏃堕棿锛屽湪缁忓巻max_fails鍚庯紝鏆傚仠鏈嶅姟

 

鍦ㄤ竴涓猯ocation涓?/strong>

location ~\.jsp$

銆€銆€proxy_pass http://tomcat_server;銆€銆€#璋冪敤璧勬簮姹?/span>

銆€銆€proxy_set_header Host $http_host;銆€銆€#娣诲姞鍙嶅悜浠g悊澶?/span>

2.鍒涘缓涓€涓蒋杩炴帴

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

3.璧锋湇鍔?/strong>

killall -HUP nginx

娉細濡傛灉鍚庣鏈嶅姟鍣ㄨ缃湁绫讳技闃茬洍閾炬垨鑰呮牴鎹甴ttp璇锋眰澶翠腑鐨刪ost瀛楁鏉ヨ繘琛岃矾鐢辨垨鍒ゆ柇鍔熻兘鐨勮瘽锛屽鏋滃弽鍚戜唬鐞嗗眰鐨刵ginx涓嶉噸鍐欒姹傚ご涓殑host瀛楁锛屽皢浼氬鑷磋姹傚け璐ワ紝鎶?00閿欒銆?/strong>

 

以上是关于nginx鍩轰簬HTTP瀹炵幇璐熻浇鍧囪 tomcat的主要内容,如果未能解决你的问题,请参考以下文章

鍩轰簬Haproxy鏋勫缓璐熻浇鍧囪 闆嗙兢

浜斿垎閽熺湅鎳?Nginx 璐熻浇鍧囪

MySQL+MMM实现MySQL高可用

璐熻浇鍧囪

璐熻浇鍧囪 涔?LVS

Linux璐熻浇鍧囪 鍜屼腑闂翠欢

(c)2006-2024 SYSTEM All Rights Reserved IT常识