Overview of this article:
JSP is a dynamic web technology standard. The method used is to insert program segments and JSP tags into HTML files to form JSP files. Using JSP to develop WEB applications can be developed across platforms. But jsp requires a javaEE server, and jsp files cannot be run under Nginx. This article will introduce how to access jsp file resources through Nginx and tomcat.
Configuration steps:
1. Environment installation
JDK, tomcat and Nginx
For the installation of JDK and tomcat, please refer to: http://www.cnblogs.com/jalja/p/6117048.html
Nginx Installation: http://www.cnblogs.com/jalja/p/6104325.html
2. Combination of Nginx and tomcat
Our Nginx server port: 80; tomcat port number: 8080
In the Nginx configuration file directory Create a jsp.conf file under (/usr/local/nginx/conf) with the following content:
user nobody; worker_processes 1; events { worker_connections 1024; } http { server { #============监听的Nginx端口======== listen 121.42.41.143:80; server_name 121.42.41.143; access_log logs/host.access.log combined; #============对不同请求的处理============= location ~ \.(jsp|jspx|do|action)?$ { #=============tomcat的资源位置============ root /usr/local/tomcat1.7/webapps/jsp; 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://121.42.41.143:8080; } } }
3. Close the nginx server, restart and load the jsp.conf configuration file
Close the Nginx server: [root@iZ28b4kreuaZ conf]# killall -9 nginx
Start the Nginx server and load the jsp.conf configuration file: [root@iZ28b4kreuaZ conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/jsp. conf
4. Whether the test is successful:
Access the Nginx server http://121.42.41.143/jsp/index.jsp
The principle of accessing Jsp under Nginx: when the user accesses .jsp .jspx .do .action When requesting resources, Nginx hands such requests to its proxy server (tomcat server) for processing.