简介:
JSP是一种动态网页技术标准。使用的方式是在HTML文件中插入程序段和JSP标记,而形成JSP文件。使用JSP开发WEB应用可以跨平台开发。但jsp需要javaEE服务器,在Nginx下是无法运行jsp文件的。本文通过nginx访问tomcat部署web应用的jsp网页
Nginx服务器端口:80
tomcat端口号:8080
1. 新建nginx配置文件jsp.conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
#============监听的Nginx端口========
listen 80;
server_name localhost;
access_log logs/host.access.log combined;
#============对不同请求的处理=============
location ~ \.(jsp|jspx|do|action)?$
{
#=============tomcat的资源位置============
#如果windows路径中有空格,用""将路径包含;如果linux, 使用\转义
root "C:/Tomcat 9.0/webapps/SpringDataRedis-0.0.1-SNAPSHOT";
index index.jsp index.jspx index.do;
#==========Nginx提供的代理============
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#=== 如果遇到.jsp .jspx .do .action 的请求就进入该服务器(tomcat)===
proxy_pass http://localhost:8080;
}
}
}
2. 重启nginx,加载jsp.conf
nginx -s stop
E:\nginx-1.15.3>nginx -c conf/jsp.conf
3. 测试访问
另外,直接访问tomcat的web项目主页: http://localhost:8080/SpringDataRedis-0.0.1-SNAPSHOT/index.jsp
原理:当用户访问 .jsp .jspx .do .action的资源时,Nginx把这样的请求交给他的代理服务器(tomcat服务器)处理