Nginx installation directory
Modify the nginx.conf file configuration load balancer Configure the Tomcat cluster and set the static and dynamic separation
#user nobody; Error_log Logs/error.log; Worker_processes 2;worker_rlimit_nofile 1024;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_forwa Rded_for "" "$gzip _ratio" $request _time $bytes _sent $request _length '; Access_log Logs/access.log Main; Include Mime.types; Default_type Application/octet-stream; CharSet gb2312; Server_names_hash_bucket_size 128; Client_header_buffer_size 32k; Large_client_header_buffers 4 32k; Client_max_body_size 8m; Sendfile on; Tcp_nopush on; Keepalive_timeout 60; Tcp_nodelay on; Fastcgi_connect_timeout 300; Fastcgi_send_timeout 300; Fastcgi_read_timeout 300; Fastcgi_buffer_size 64k; Fastcgi_buffers 4 64k; Fastcgi_busy_buffers_size 128k; Fastcgi_temp_file_write_size 128k; gzip on; Gzip_min_length 1k; Gzip_buffers 4 16k; Gzip_http_version 1.0; Gzip_comp_level 2; Gzip_types text/plain application/x-javascript text/css application/xml; Gzip_vary on; #gzip on; Upstream Tomcat_server {server localhost:9001 weight=1; #server localhost:9002 weight=1; } server {Listen 80; server_name 10.67.16.226; CharSet Utf-8; root static; #配置Nginx动静分离, defined static pages are read directly from the Nginx publishing directory. Location ~. *\. (HTM|GIF|JPG|JPEG|BMP|PNG|ICO|TXT|JS|CSS|SVG|EOT|TTF|WOFF|WOFF2) $ {root static; #static前面不加 '/' indicates the root directory from the Nginx installation directory so static State resources can be placed in the static folder, plus '/' means that our local disk root directory (such as my d://static), if the error can see logs under the Error.log #expires定义用户浏览器缓存的时间为7天, if the static page is not updated frequently, Can be set longer, which saves bandwidth and relieves pressure on the server expIres 7d; } location/{proxy_next_upstream http_502 http_504 error timeout invalid_header; Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; Proxy_pass Http://tomcat_server; } Location-^/(Web-inf)/{deny all; } error_page 502 503 504/50x.html; Location =/50x.html {root html; } } }
The static resources of my site are read from the Resource folder (note: The following page is not completely static at the end of the. HTML is local static, that is, using AJAX to push the data on the home page is mostly pushed), but each read is directly read from the resource under Tomcat, such as jquery, CSS, bootstrap and other static files I want to put them to nginx now;
Look at the following Tomcat root directory does not have the resource folder, static resources from the Nginx directly read and let the client cache; My tomcat port is 9001, the following to verify that the static file is read from Nginx;
Access local 9001 Port Tomcat
Below is the Access Nginx server (static file access Nginx dynamic by Tomcat processing);
After login
OK, it's done.
Nginx configures cache server cache static resource +tomcat cluster under Windows