First, static and dynamic separation
1, through the middleware dynamic and static requests separate request.
2, Why?
Isolated resources, reduce unnecessary consumption of a request, a request to reduce the delay.
3, Scene
May also be utilized php, fastcgi, python, etc. Processing dynamic requests
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
[root@web-01 ~]# cat ngixn.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/cp4/*.conf; }
server conf configuration
[root@web-01 ~]# cat test_mysite.conf upstream java_api{ server 127.0.0.1:8080; } server { listen 80; server_name web01.fadewalk.com; access_log /var/log/nginx/host.access.log main; root /opt/app/code/cp4/code; location ~ \.jsp$ { proxy_pass http://java_api; index index.html index.htm; } location ~ \.(jpg|png|gif)$ { expires 1h; gzip on; } }
Tomcat deployment jsp page
[root @ 01 Web-ROOT] # Tomcat Version Server Version: the Apache Tomcat / 7.0.76 Server Built: Mar 12 2019 10:11:36 UTC Server Number The: 7.0.76.0 OS the Name: Linux OS Version: 3.10.0-957.21 .2.el7.x86_64 Architecture: AMD64 the JVM Version: 1.8.0_212-B04 the JVM Vendor: the Oracle Corporation [root @ Web-01 ~] # cd / usr / report this content share / Tomcat / webapps [root @ Web-webapps 01] # mkdir ROOT [root @ Web-01 webapps] # cd ROOT / [root @ Web-01 ROOT] # pwd / usr / report this content share / Tomcat / webapps / ROOT # / usr / report this content share / Tomcat / webapps all pages directory, no ROOT directory when, needs its own new, ROOT directory as the default Web page directory, the project directory must be capitalized, the corresponding configuration [root @ 01 Web-ROOT] # LL -rw-r - r-- 1 root root 343 Jun 17 02.: 14 java_test.jsp Total 4
Access page
<html lang="en"> <head> <meta charset="UTF-8" /> <title>测试ajax和跨域访问</title> <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> </head> <script type="text/javascript"> $(document).ready(function(){ $.ajax({ type: "GET", url: "http://jeson.t.imooc.io/java_test.jsp", success: function(data) { $("#get_data").html(data) }, error: function() { alert("fail!!!,请刷新再试!"); } }); }); </script> <body> <h1>测试动静分离</h1> <img src="http://jeson.t.imooc.io/img/nginx.png"/> <div id="get_data"><div> </body> </html>
Handle dynamic page requests
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <HTML> <HEAD> <TITLE>JSP Test Page</TITLE> </HEAD> <BODY> <% Random rand = new Random(); out.println("<h1>Random number:</h1>"); out.println(rand.nextInt(99)+100); %> </BODY> </HTML>
test