手机版
你好,游客 登录 注册
背景:
阅读新闻

Nginx+Tomcat实现动静分离

[日期:2012-03-14] 来源:51cto  作者:dl528888 [字体:大 中 小]

2、安装、配置tomcat

先安装jdk

  1. wget http://download.Oracle.com/otn-pub/Java/jdk/7u3-b04/jdk-7u3-linux-x64.rpm  
  2. chmod 755 jdk-7u3-linux-x64.rpm  
  3. rpm -ivh jdk-7u3-linux-x64.rpm  
在/etc/profile里设置环境变量
  1. JAVA_HOME=/usr/java/jdk1.7.0  
  2. CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib   
  3. PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin   
  4. export PATH CLASSPATH JAVA_HOME   
然后在source /etc/profile使这个改变生效

安装tomcat

  1. wget http://mirror.bjtu.edu.cn/apache/tomcat/tomcat-7/v7.0.25/bin/apache-tomcat-7.0.25.tar.gz  
  2. tar zxvf apache-tomcat-7.0.25.tar.gz  
  3. cp -R apache-tomcat-7.0.25 /usr/local/tomcat  

启动tomcat

  1. /usr/local/tomcat/bin/startup.sh 
之后打开http://localhost:8080就能看到tomcat的默认界面了
下面我们来修改tomcat的首页
我在$tomcat/webapps/下建了个html目录作为我网站的默认目录,在html中有一个index.html文件,该文件要作为我网站的默认主页。
首先,修改$tomcat/conf/server.xml文件。
在server.xml文件中,有一段如下:
 
  1. ……  
  2. <engine name="Catalina" defaultHost="localhost"> 
  3. <host name="localhost" appBase="webapps" 
  4. unpackWARs="true" autoDeploy="true" 
  5. xmlValidation="false" xmlNamespaceAware="false"> 
  6. ……  
  7. <host> 
  8. </engine> 
  9. ……  

在<host></host>标签之间添加上:
 

  1. <Context path="" docBase="html" debug="0" reloadable="true" /> 
path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;

docBase是虚拟目录的路径,它默认的是$tomcat/webapps/ROOT目录,现在我在webapps目录下建了一个html目录,让该目录作为我的默认目录。

debug和reloadable一般都分别设置成0和true。

然后,修改$tomcat/conf/web.xml文件。
在web.xml文件中,有一段如下:

  1. <welcome-file-list> 
  2. <welcome-file>index.html</welcome-file> 
  3. <welcome-file>index.htm</welcome-file> 
  4. <welcome-file>index.jsp</welcome-file> 
  5. </welcome-file-list> 

在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:

  1. <welcome-file>html</welcome-file> 
修改完成之后,重启tomcat即可看到index.html里的内容
tomcat服务器的ip为10.1.88.168

在test4建立test.jsp、test1.do文本,内容如下

tomcat的首页内容

test.jsp内容

test1.do内容

nginx的首页内容

在nginx里查看动态请求

nginx处理test1.do

现在nginx+tomcat就实现了动静分离技术。

linux
相关资讯       Tomcat  Nginx 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款