Nginx server: Access jsp and nginxtomcat in combination with tomcat
This document uses centos
Overview:
JSP is a technical standard for dynamic web pages. You can insert a program segment and JSP tag into an HTML file to form a JSP file. WEB applications developed using JSP can be developed across platforms. However, jsp requires the javaEE server. jsp files cannot be run in Nginx. This article describes how to use Nginx and tomcat to access jsp file resources.
Configuration steps:
1. Environment Installation
JDK, tomcat, and Nginx
JDK and tomcat installation, see: http://www.cnblogs.com/jalja/p/6117048.html
Nginx installation: http://www.cnblogs.com/jalja/p/6104325.html
2. Integrate Nginx with tomcat
Our Nginx server port: 80; tomcat port number: 8080
Create a jsp. conf file in the Nginx configuration file directory (/usr/local/nginx/conf). The file content is as follows:
User nobody; worker_processes 1; events {worker_connections 1024 ;} http {server {#============= listening Nginx port ======= listen 121.42.41.143: 80; server_name 121.42.41.143; access_log logs/host. access. log combined ;#============== processing different requests =================== location ~ \. (Jsp | jspx | do | action )? $ {#============== Tomcat resource location ========== root/usr/local/tomcat1.7/ webapps/jsp; index. jsp index. jspx index. do ##========== proxy provided by 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; #== If yes. jsp. jspx. do. the action request enters the server (tomcat) === proxy_pass http: // 121.42.41.143: 8080 ;}}}
3. Disable the nginx server, restart and load the jsp. conf configuration file.
Disable 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. Check whether the test is successful:
Access Nginx server http: // 121.42.41.143/jsp/index. jsp
How to access Jsp in Nginx: when a user accesses resources of. jsp. jspx. do. action, Nginx sends such requests to its proxy server (tomcat server) for processing.