1.下载安装
tar zxvf jdk-7u9-linux-i586.tar.gz -C /usr/local/
mv /usr/local/jdk1.7.0_09 /usr/local/jdk
tar zxvf apache-tomcat-7.0.32.tar.gz -C /usr/local/
mv /usr/local/apache-tomcat-7.0.32/ /usr/local/tomcat
vi /etc/profile
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH="$PATH:$JAVA_HOME/bin"
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
source /etc/profile
2.配置nginx+tomcat
vi /usr/local/nginx/conf/nginx.conf //将server段大概修改成下面酱紫
server {
listen 80;
srver_name www.test.com ;
index index.html index.jsp;
root /test;
location ~ \.jsp$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080 ;
}
location ~ \.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ \.(js|css)$ {
expires 1h;
}
}
cd /usr/local/tomcat/conf
vi server.xml //在最下面Host处,再添加一个Host
<Host name= www.test.com appBase="/test" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/test/" reloadable="true" />
</Host>
mkdir /test
cp -rf /usr/local/tomcat/webapps /test/
3.启动tomcat nginx
/usr/local/tomcat/bin/startup.sh
/usr/local/nginx/sbin/nginx
4.测试
cd /test
touch hello.jsp
vi hello.jsp
<html>
<body>
<center>
now time is:<%=new java.util.Date()%>
</center>
</body>
</html>
用浏览器访问 http://www.test.com/hello.jsp,如果出来下图就成功了