先实现jsp页面,基于tomcat
工程结构
test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>测试页面,jsp from tomcat</h1>
<img alt="展示" src="${pageContext.request.contextPath }/static/images/bbb.jpg">
</body>
</html>
将工程代码打包,放入tomcat容器里面,默认8080端口
http://www.test.com:8080/tomcat-test/test.jsp
查看这里的服务器为apache服务器
配置nginx
配置80端口,jsp动态类容走tomcat,静态内容走nginx
server {
listen 80;
server_name www.test.com;
location ~* \.jsp$ {
proxy_pass http://localhost:8080;
}
location ~* \.(jpg|js|png|css)$ {
root /app/apache-tomcat-7.0.93/webapps;
expires 3d;
}
}
访问:http://www.test.com/tomcat-test/test.jsp
服务器为nginx
查看nginx代理日志