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

Nginx optimization-process management, web page compression, hotlink protection

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Main points of content:

Process Management of nginx Optimization

Nginx optimized Web Page Compression

Hotlink protection optimized by nginx

Experimental environment:

On the basis of compiling and installing nginx

I. process management of nginx optimization

1. Time-out access:

Vim / usr/local/nginx/conf/nginx.conf http {... keepalive_timeout 65 180; # whichever is the latter. You can set client_header_timeout 80 at http\ server\ locati on; # the timeout of waiting for the client to send the request header will send 408 error client_body_timeout 80; # set the timeout of the client input request body.}

2. Change the number of processes

Ps aux | grep nginx # # View the current number of processes. A main process contains a child process

A, add cpu

Add cpu in the lower right corner of the virtual machine

B. Restart the service

Init 6

C. Check the cpu situation

Cat / proc/cpuinfo

D. Modify the configuration file

Vim / usr/local/nginx/conf/nginx.confworker_processes 2; # worker process is 2 (modify the same or twice the number of cores) worker_cpu_affinity 01 10; # average allocation number 1 2 (each process is handled by a different cpu)

II. Web page compression

1. Configure compression in the configuration file

Vim / usr/ local/nginx/ conf/nginx. Conf gzip on; # remove # enable gzip compression function gzip_min_length 1k; # compression threshold gzip_buffers 4 16k; # buffer size 4 16k buffer size gzip_http_version 1.1; # compressed version wood gzip_comp_level 6 # Compression ratio, minimum 1, fast processing speed, slow transmission speed, 9 maximum compression ratio, slow processing speed, fast transmission speed gzip_types text/plain application/x-javascript text/css image/jpg image/jpeg image/png image/gif application/xml text/javascript application/x-httpd-php application/javascript applicationion/json; gzip_disable "MSIE [1-6]\." # configure to disable gzip condition and support regular, which means that gzip gzip_vary on; is not enabled below ie6. # choosing to support very header allows the front-end cache server to cache gzip-compressed pages

2. Insert an jpg image into the home page of the site for testing.

Cp / error / usr/local/nginx/htmlvim index.html

Third, hotlink protection optimized by nginx

Add hotlink jump settings to the nginx configuration file

There are two configuration methods:

First kind

Vim / usr/local/nginx/conf/nginx.conf location ~ *\. (jpg | gif | swf) ${# the file type that requires hotlink protection resources valid_referers none blocked * .lulu.com; if ($invalid_referer) {rewrite ^ / # if someone illegally steals the resources, return a hotlink protection map}}

The second kind:

Location / img/ {# img is the relative directory, which is the img directory valid_referers none blocked server_names * .lulu.com under the html directory; # the domain name or IP if ($invalid_referer) {rewrite ^ / https://cache.yisu.com/upload/information/20200309/28/13243.jpg; allowed to access this directory }}

More aginx optimization and apache optimization can be viewed on my home page.

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