Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The number of change processes optimized in depth by Nginx and the configuration of web page compression

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Nginx deep optimization changes the number of processes and configuration page compression foreword

This article describes Nginx changing the number of processes and configuring web page compression.

1. Change number of processes

In a high-concurrency environment, more nginx processes need to be started to ensure fast response and avoid blocking. The ps aux command can be used to check the number of nginx runs.

[root@localhost ~]# ps aux | grep nginxroot 12848 0.0 0.0 20544 616 ? Ss 07:47 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 12849 0.0 0.0 23072 1400 ? S 07:47 0:00 nginx: worker processroot 67138 0.0 0.0 112732 968 pts/1 R+ 08:37 0:00 grep --color=auto nginx

So if you need to change the number of processes, we must first increase the original cpu parameters appropriately, of course, in the real project is automatically extended. At present, the number of my CPU processors is 4, so there is no need to shut down the experiment. We can grep out the necessary information under the/proc directory.

[root@localhost ~]# grep 'processor' /proc/cpuinfo processor : 0processor : 1processor : 2processor : 3

Modify configuration file (nginx) and restart service

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf[root@localhost ~]# sed -n '3,4p' /usr/local/nginx/conf/nginx.confworker_processes 4; #Number of modifications worker_cpu_affinity 0001 0010 0100 1000; #Assign different processes to different CPUs [root@localhost ~]# service nginx stop[root@localhost ~]# service nginx start[root@localhost ~]# ps aux| grep nginxroot 60074 0.0 0.0 20544 616 ? Ss 09:29 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 60075 0.0 0.0 23072 1400 ? S 09:29 0:00 nginx: worker processnginx 60076 0.0 0.0 23072 1396 ? S 09:29 0:00 nginx: worker processnginx 60077 0.0 0.0 23072 1400 ? S 09:29 0:00 nginx: worker processnginx 60078 0.0 0.0 23072 1400 ? S 09:29 0:00 nginx: worker processroot 60169 0.0 0.0 112732 972 pts/1 R+ 09:29 0:00 grep --color=auto nginx2. Web compression

Nginx's ngx_http_gzip_module compression module provides the ability to compress file content, allowing the Nginx server to compress the output content before sending it to the client, which can save website bandwidth and improve user experience.

Before compression it looks like this:

Turn on compression and set parameters as follows

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf[root@localhost ~]# sed -n '37,44p' /usr/local/nginx/conf/nginx.conf gzip on; #Turn on compression gzip_min_length 1k; #More than 1kb Start compression gzip_buffers 4 16k; #Size is 4 16k buffer sizes gzip_http_version 1.1; gzip_comp_level 6; #compression ratio, 1-9 1 fastest compression 9 highest compression ratio gzip_types text/plain application/x-javascript text/css image/jpg image/jpeg image/png image/gif; gzip_disable "MSIE [1-6]\. "; #Configure disable gzip condition, which means ie6 is not supported by the following browsers gzip_vary on;#Select Support Vary header to enable front-end cache servers to cache gzipped pages [root@localhost ~]# service nginx stop[root@ localhost ~]#service nginx start[root@localhost named]# systemctl stop firewalld.service [root@ localhost named]# setenforce 0[root@ localhost named]# cd -/root[root@localhost ~]# netstat -antp| grep namedtcp 0 0 192.168.68.145:53 0.0.0.0:* LISTEN 78380/named tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 78380/named tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 78380/named tcp 0 0 192.168.68.145:45416 198.97.190.53:53 ESTABLISHED 78380/named tcp6 0 0 ::1:53 :::* LISTEN 78380/named tcp6 0 0 ::1:953 :::* LISTEN 78380/named [root@localhost ~]# netstat -antp | grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 80863/nginx: master

Then grab the package again after emptying the cache on the win10 tester, and the result is as follows

Summary: This article is mainly about nginx service process management and web page compression optimization settings.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report