Home >Backend Development >PHP Tutorial >nginx and tomcat server optimization nginx tomcat load balancing nginx tomcat dynamic and static separation nginx tomcat access
1.Nginx server optimization (mainly related to some attribute configurations of the Nginx.conf file)
# It is generally recommended to be less than the number of CPUs. Generally, the process runs on the CPU, and Nginx adopts time-based non-blocking multiplexing epoll Model
1.worker_processes
#Bind the work process to a specific CPU to avoid the overhead of switching processes between CPUs (8-core setting 00000001 00000010 00000100 00001000)
2.worker_cpu_affinity 000 1 0010 0100 1000
#The maximum file description that a process can open Number of descriptors 502 error (maximum number of system descriptors supported/number of processes)
3.worker_rlimit_nofile
#Maximum number of connections allowed per process (when doing a static server: number of client connections = worker_connections*number of processes/2 Doing a reverse proxy server Number of customer connections = worker_connections*number of processes/4)
4.worker_connections 200000
#Set the printing level of the access log and error log in http or turn it off to reduce IO
5.http{ access_log offl;error_log logs/error.log crit}
#Start the kernel copy mode to maintain the highest IO efficiency
6.http{ sendfile on}
#Keep the connection time long. The advantage is to reduce the number of connections created and speed up the response. However, the number of responding connections will be limited (up to 100 connections, and new connections cannot be created before they are released) The better the effect, the more server resources will be occupied.
8.gzip on /gzip_min_length 1000/gzip_comp_level
#Selection of compressed file type. If some files have poor compression effect, choose not to compress them to reduce server performance loss.
9.gzip_type
#Maximum cache number, unused file survival period
10. open_file_cache max=655350 inactive=20s;
open_file_cache_valid 30s #Verify the cache validity interval
open_file_cache_min_uses 2 The minimum number of uses of the file within the validity period
====》Cannot reach 2 times in 20 seconds, and the hit rate detection once in 30 seconds has not been If the standard is met, remove it
2. Tomcat optimization
1. First optimize the catalina.sh file in the bin directory of the Tomcat installation directory
(1) Set the heap memoryJAVA_OPTS=$JAVA_OPTS -server -Xms1024m -Xmx2048m
(2 ) Set PermGen memory (java.lang.OutOfMemoryError) jdk1.8 does not need to set
-XX:PermSize=256m -XX:MaxPermSize=512m
(3) Set java to run in a mode without graphics display
-Djava. awt.headless=true
2. Set server.xml
Set some parameters of
The above introduces nginx and tomcat server optimization, including tomcat and nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.