RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Tomcat(二):Nginx反向代理实现Tomcat动静分离

Tomcat(二):Nginx反向代理实现Tomcat动静分离 实验拓扑:
实验环境:

OS:CentOS-6.7-x86_64

创新互联建站长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为阿克塞哈萨克族自治企业提供专业的网站制作、成都网站设计阿克塞哈萨克族自治网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

Nginx:

IP:192.168.1.4

Tomcat:

IP:192.168.1.5 实验流程:

Tomcat:

先安装Jvm:openjdk:

[root@node1 ~]# yum install java-1.7.0-openjdk [root@node1 ~]# java -version java version "1.7.0_79" OpenJDK Runtime Environment (rhel-2.5.5.4.el6-x86_64 u79-b14) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

安装tomcat:

官网:http://tomcat.apache.org

[root@node1 ~]# tar xf apache-tomcat-7.0.65.tar.gz -C /usr/local/ [root@node1 ~]# cd /usr/local/ [root@node1 local]# ln -sv apache-tomcat-7.0.65 tomcat "tomcat" -> "apache-tomcat-7.0.65" [root@node1 ~]# vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$CATALINA_HOME/bin:$PATH [root@node1 ~]# source /etc/profile.d/tomcat.sh

提供脚本:

[root@node1 ~]# cat /etc/rc.d/init.d/tomcat #!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. # JAVA_OPTS=\'-Xms64m -Xmx128m\' JAVA_HOME=/usr/lib/jvm/jre CATALINA_HOME=/usr/local/tomcat export JAVA_HOME CATALINA_HOME case $1 in start) exec $CATALINA_HOME/bin/catalina.sh start ;; stop) exec $CATALINA_HOME/bin/catalina.sh stop;; restart) $CATALINA_HOME/bin/catalina.sh stop sleep 2 exec $CATALINA_HOME/bin/catalina.sh start ;; *) echo "Usage: `basename $0` {start|stop|restart}" exit 1 ;; esac [root@node1 ~]# chmod +x /etc/rc.d/init.d/tomcat [root@node1 ~]# chkconfig tomcat --add

定义管理页面用户名及密码:

[root@node1 ~]# cd /usr/local/tomcat/conf [root@node1 conf]# vim tomcat-users.xml [root@node1 conf]# service tomcat start [root@node1 conf]# chkconfig tomcat on

访问测试:

部署站点文件:

[root@node1 ~]# mkdir -p /tomcat/webapps [root@node1 ~]# unzip JspRun!_6.0.0_GBK.zip [root@node1 ~]# mv upload /tomcat/webapps/jsprun [root@node1 ~]# cd /tomcat/webapps [root@node1 webapps]# chmod -R 777 jsprun [root@node1 webapps]# cd jsprun [root@node1 jsprun]# vim config.properties dbhost = 192.168.1.5 dbport=3306 dbuser = jruser dbpw = jrpass dbname = jrdb

定义虚拟主机,并重启tomcat:

[root@node0 ~]# cd /usr/local/tomcat [root@node0 tomcat]# vim conf/server.xml [root@node1 ~]# service tomcat restart

安装并启动mysql:

[root@node0 mysql-5.5-rpm]# yum install MySQL-shared-compat-5.5.48-1.el6.x86_64.rpm MySQL-client-5.5.48-1.el6.x86_64.rpm MySQL-server-5.5.48-1.el6.x86_64.rpm [root@node0 ~]# service mysql start [root@node0 ~]# chkconfig mysql on

创建数据库,并赋予权限:

[root@node0 ~]# mysql mysql> create database jrdb; Query OK, 1 row affected (0.00 sec) mysql> grant all on jrdb.* to \'jruser\'@\'192.168.1.5\' identified by \'jrpass\'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

安装站点,并访问测试:

Nginx:

安装并配置Nginx:

[root@node0 ~]# yum install nginx

动态页面重定向至tomcat:

[root@node0 ~]# cd /etc/nginx/conf.d/ [root@node0 conf.d]# vim default.conf server { listen 80; server_name node0.chencer.org; index index.jsp; location ~* .(jsp|do)$ { proxy_pass http://192.168.1.5:8080; } } [root@node0 conf.d]# service nginx start [root@node0 conf.d]# chkconfig nginx on

访问测试:

部署站点静态文件:

[root@node0 ~]# mkdir -p /web/jsprun [root@node0 ~]# scp -r node1:/tomcat/webapps/jsprun/* /web/jsprun/

编辑配置文件:

[root@node0 conf.d]# vim default.conf server { listen 8080; server_name 192.168.1.4; index index.jsp; location / { root /web/jsprun; index index.html; } } server { listen 80; server_name node0.chencer.org; index index.jsp; location / { proxy_pass http://192.168.1.5:8080; } location ~.(html|htm|xml|gif|jpg|jpeg|ico|swf)$ { proxy_pass http://192.168.1.4:8080; } location ~* .(jsp|do)$ { proxy_pass http://192.168.1.5:8080; } } [root@node0 ~]# service nginx restart

访问测试:


当前文章:Tomcat(二):Nginx反向代理实现Tomcat动静分离
当前路径:http://lswzjz.com/article/cgpjoh.html