In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
1) static resource types
2) static resource scenarios
3) static resource allocation syntax
4) static resource file compression
5) static resource browser cache
6) static resource hotlink protection
1) static resource types
Nginx as a static resource web server deployment configuration, transmission is very efficient, often used for static resource processing, request, static and static separation!
Files generated by non-server dynamic running belong to static resources!
Type type browser rendering HTML, CSS, JS picture JPEG, GIF, PNG video FLV, MP4 file TXT, arbitrary download file 2) static resource scene
Minimize the delay of static resource transmission!
As shown in the figure:
3) static resource configuration syntax 1) efficient file reading-- > sendfileSyntax:sendfile on | off; Default:sendfile off; Context:http, server, location, if in location; 2) improve network transmission efficiency-- > nopushSyntax:tcp_nopush on | off; Default:tcp_nopush off; Context:http, server, location; function: when sendfile is enabled, the 'transmission efficiency' of the network packet is improved; 3) the configuration corresponding to tcp_nopush tcp_nodelaySyntax: tcp_nodelay on | off Default: tcp_nodelay on; Context:http, server, location; creation: under the keepalive connection, the real-time transmission of the network is mentioned; 4) static resource file compression
Nginx can enable compression before sending the response message to the client, which can effectively save bandwidth and improve the speed of the response client.
1) gzip compression configuration syntax Syntax: gzip on | off; Default: gzip off; Context: http, server, location, if in location; operation: transmission compression; 2) gzip compression ratio configuration syntax Syntax: gzip_comp_level level; Default: gzip_comp_level 1; Context: http, server, location; compression itself consumes server performance 3) gzip compression protocol version Syntax: gzip_http_version 1. 0; Default: gzip_http_version 1. 1; Context: http, server, location. 4) expand compression module Syntax: gzip_static on | off | always; Default: gzip_static off; Context: http, server, location; Writing: pre-read gzip function 5) Image compression case [root@nginx ~] # mkdir-p / soft/code/images [root@nginx ~] # vim / etc/nginx/conf.d/static_server.confserver {listen 80; server_name 192.168.1.10; sendfile on; access_log / var/log/nginx/static_access.log main; location ~. *\. (jpg | gif | png) ${gzip on Gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/json application/x-javascript application/ css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png; root / soft/code/images;}} [root@nginx ~] # nginx-t [root@nginx ~] # nginx-s reload
As the compression effect of the picture is not very good, so only the configuration is attached here!
6) File compression case [root@nginx ~] # mkdir-p / soft/code/doc [root@nginx ~] # vim / etc/nginx/conf.d/static_server.confserver {listen 80; server_name 192.168.1.10; sendfile on; access_log / var/log/nginx/static_access.log main; location ~. *\. (txt | xml) ${gzip on Gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/json application/x-javascript application/ css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png; root / soft/code/doc }} [root@nginx ~] # nginx-t [root@nginx ~] # nginx-s reload 1) gzip file compression is not enabled
2) enable gzip file compression
5) static resource browser cache
Caching mechanism defined by HTTP protocol (e.g. Expires; Cache-control, etc.)
1) browser has no cache
Browser request-- > No cache-- > request web server-- > request response-- > render
2) the browser has a cache
Browser request-> have cache-> verify expiration-> whether there is update-> render check whether the Expires HTTP1.0 expires, Etag () Last-Modified header information verification in Cache-Control (max-age) HTTP1.1 protocol Last-Modified (specific time) 1) cache configuration syntax expiresSyntax: expires [modified] time; Default: expires off; Context: http, server, location, if in location; actions: add Cache-Control Expires header 2) configure static resource cache [root@nginx conf.d] # vim static_server.conf server {listen 80; server_name 192.168.1.10; sendfile on; access_log / var/log/nginx/static_access.log main; location ~. *\. (txt | js | css | html) ${root / soft/code/doc; expires 1h } location ~. *\. (jpg | gif | png) ${root / soft/code/images; expires 7d;}} [root@nginx conf.d] # nginx-t [root@nginx conf.d] # nginx-s reload
Browser test results:
3) configure static files not to cache [root@nginx conf.d] # vim static_server.confserver {listen 80; server_name 192.168.1.10; sendfile on; access_log / var/log/nginx/static_access.log main; location ~. *\. (txt | js | css | html) ${root / soft/code/doc; add_header Cache-Control no-store Add_header Pragma no-cache;} location ~. *\. (jpg | gif | png) ${root / soft/code/images; expires 7d;}} [root@nginx conf.d] # nginx-t [root@nginx conf.d] # nginx-s reload
Browser test results:
6) static resource hotlink protection
Hotlink refers to displaying the content that is not on the server in the domain, obtaining the resource address of his server through the technical segment, bypassing the resource display address, providing this content to customers in the server, lightening the burden on the server because of the real space and traffic to "distinguish" the server.
The idea of hotlink protection: distinguish which requests are "normal" user requests
Based on http_refer hotlink protection configuration module:
Syntax: valid_referers none | blocked | server_names | string...; Default:-Context: server, location
Another nginx server (in the initial case), write the html file:
[root@nginx02 conf.d] # vim / usr/share/nginx/html/dl.html pachong
[root@nginx02 conf.d] # nginx-t [root@nginx02 conf.d] # nginx-s reload
Normal access to the first service:
The second child server embezzled the picture of the first server:
2) enable hotlink protection [root@nginx conf.d] # vim static.confserver {listen 80; server_name 192.168.1.10; valid_referers none blocked 192.168.1.10; location ~. *\. (jpg | gif | png) ${if ($invalid_referer) {return 403; break } root / soft/code/images;}} [root@nginx conf.d] # nginx-t [root@nginx conf.d] # nginx-s reload
Access the second server again:
-this is the end of this article. Thank you for reading-
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.