nginx实现nginx+tomcat动静分离
内网服务器ip:192.168.8.10
lamp环境搭建
(1)lamp环境搭建不再多说,请参见51cto博客
(2)编辑nginx.conf文件
在server段中添加如下:
location ~(\.jsp)|(\.do)$ { proxy_pass http://192.168.8.10:8080; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
2.下载安装jdk
此处使用的的jdk-7u79-linux-x64.tar.gz
cd /usr/local/src//加压缩jdktar xzvf jdk-7u79-linux-x64.tar.gzmv jdk1.7.0_79 /usr/local///编辑/etc/profile,末尾添加如下export JAVA_HOME=/usr/local/jdk1.7.0_79export JAVA_BIN=/usr/local/jdk1.7.0_79/binexport CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$JAVA_HOME/jre/bin:$JAVA_BIN:$PATH//编辑完成后,执行以下命令使上述生效source /etc/profile//执行java及javac有相应提示输出javajavac
3.下载安装tomcat
//下载apache-tomcat-7.0.69.tar.gz cd /usr/local/srctar xzvf apache-tomcat-7.0.69.tar.gz mv apache-tomcat-7.0.69 /usr/lcoal/tomcat//创建html目录mmkdir -p /usr/local/tomcat/webapps/html//创建文件cat /usr/local/tomcat/webapps/html/index.htmlThis is Tomcat, index.htmlcat /usr/local/tomcat/webapps/html/test.jspThis is Tomcat, test.jsp cat /usr/local/tomcat/webapps/html/test.doThis is Tomcat, test.do//编辑/usr/local/tomcat/conf/server.xm// 为添加的内容 //编辑/usr/local/tomcat/conf/web.xml // html 为添加的内容html index.html index.htm index.jsp
4.重启nginx及启动tomcat
/etc/init.d/nignx restart/usr/local/tomct/bin/startup.sh
5.检测
(1)在浏览器地址栏输入192.168.8.10:8080输出以下:
This is Tomcat, index.html
(2)在浏览器地址栏输入192.168.8.10/test.jsp输出以下:
This is Tomcat, test.jsp
(3)在浏览器地址栏输入192.168.8.10/test.do输出以下:
This is Tomcat, test.do
http://www.centoscn.com/CentosServer/cluster/2014/0316/2580.html