1. Optimize Nginx concurrency[root@proxy ~]# ab -n 2000 -c 2000 http://192.168.4.5/ Benchmarking 192.168.4.5 (be patient) socket: Too many open files (24) //Prompt that there are too many open files Modify the Nginx configuration file to increase concurrency [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf .. .. worker_processes 2; //Same as the number of CPU cores events { worker_connections 65535; //The maximum number of concurrent connections per worker use epoll; } .. .. [root@proxy ~]# nginx -s reload 2. Optimize Linux kernel parameters (maximum number of files)[root@proxy ~]# ulimit -a //View all attribute values [root@proxy ~]# ulimit -Hn 100000 //Set hard limit (temporary rule) [root@proxy ~]# ulimit -Sn 100000 //Set soft limit (temporary rule) [root@proxy ~]# vim /etc/security/limits.conf .. .. * soft nofile 100000 * hard nofile 100000 #The configuration file is divided into 4 columns, as follows: #User or group hard limit or soft limit The value of the item limit that needs to be restricted Test server concurrency after optimization [root@proxy ~]# ab -n 2000 -c 2000 http://192.168.4.5/ 3. Optimize Nginx packet header cache[root@proxy ~]# cat lnmp_soft/buffer.sh #!/bin/bash URL=http://192.168.4.5/index.html? for i in {1..5000} do URL=${URL}v$i=$i done curl $URL //After 5000 cycles, a long URL address bar is generated [root@proxy ~]# ./buffer.sh .. .. <center><h1>414 Request-URI Too Large</h1></center> //Prompt that the header information is too large Modify the Nginx configuration file to increase the packet header cache size [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf .. .. http { client_header_buffer_size 1k; //Default request header information cache large_client_header_buffers 4 4k; //Number and capacity of caches for large request header information.. .. } [root@proxy ~]# nginx -s reload 4. Compress the page[root@proxy ~]# cat /usr/local/nginx/conf/nginx.conf http { .. .. gzip on; //Turn on compression gzip_min_length 1000; //Small files are not compressed gzip_comp_level 4; //Compression ratio gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; //Compress specific files, refer to mime.types for types .. .. 5. Server Memory Cachehttp { open_file_cache max=2000 inactive=20s; open_file_cache_valid 60s; open_file_cache_min_uses 5; open_file_cache_errors off; //Set the server to cache a maximum of 2000 file handles, and close file handles that have no requests within 20 seconds. //The validity period of a file handle is 60 seconds, and it expires after 60 seconds. //Only files accessed more than 5 times will be cached.} 6. Browser local cache static data[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { expires 30d; //Define the client cache time to 30 days} } [root@proxy ~]# cp /usr/share/backgrounds/day.jpg /usr/local/nginx/html [root@proxy ~]# nginx -s reload This concludes this article on the six methods of nginx optimization. For more relevant nginx optimization content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Robots.txt detailed introduction
>>: Summary of 4 methods of div+css layout to achieve 2-end alignment of css
MySQL full text search Chinese solution Recently,...
1. Install mysql: udo apt-get install mysql-serve...
In a page, there are many controls (elements or ta...
I accidentally found that Vue.$set was invalid in...
Optimistic Locking Optimistic locking is mostly i...
Mainly use the preserve-3d and perspective proper...
Bash Initialization Files Interactive login shell...
Mysql limit paging statement usage Compared with ...
I see many novice students doing front-end develop...
I used vue and bootstrap to make a relatively sim...
Install mysql5.7 under win, for your reference, t...
Table of contents 1. Parent component passes valu...
1. Download from the official website and unzip h...
Table of contents WebAPI DOM DOM Tree DOM element...
Preface WeChat Mini Programs provide new open cap...