In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Configure Nginx to realize Web Page Compression function
Nginx's ngx http .gzip _ module compression module provides the function of compressing the file content, allowing the Nginx server to compress the output before sending it to the client, so as to save the website bandwidth and enhance the user's access experience. The corresponding compression function parameters can be added to the configuration file to optimize the compression performance.
Compression function parameter gzip on: enable gzip compression output gzip_ min_ length 1k: used to set the minimum number of bytes of pages allowed to be compressed gzip_ buffers 416k: apply for 4 units of 16k memory as compression result stream cache. The default value is to apply for memory space of the same size as the original data to store gzip compression result zip_ http_ version 1.0: used to set identify http protocol version The default is 1.1.At present, most browsers support gzip decompression, but the processing is the slowest and consumes server CPU resources gzip_ _ comp_ level 2: used to specify gzip compression ratio, 1 compression ratio is the smallest and processing speed is the fastest 9 the compression ratio is the largest, the transmission speed is fast, but the processing speed is the slowest. Use the default gzip_ types text/plain: compression type, which is to enable the compression function of which web page documents gzip_ vary on: option allows the front-end cache server to cache the gzip compressed page compression example demo 1, compile and install Nginx service
Step 1: remotely obtain the source code package on Windows and mount it to Linux
[root@localhost] # smbclient-L / / 192.168.235.1Enter SAMBA\ root's password: Sharename Type Comment- LNMP Disk [root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.235.1/LNMP / abcPassword for root@//192.168.235.1/LNMP: [root @ localhost ~] # [root@localhost ~] # ls / abcDiscuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gzerror.png nginx-1.12.2.tar.gzgame.jpg php-7.1.10.tar.bz2mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz
Step 2: decompress the source package
[root@localhost ~] # cd / abc [root@localhost abc] # tar zxvf nginx-1.12.0.tar.gz-C / opt [root@localhost abc] # ls / optnginx-1.12.0 rh
Step 3: download and install the compiler package
[root@localhost abc] # cd / opt [root@localhost opt] # yum install-y\ > gcc\ / / C language > gcc-c++\ / / C++ language > pcre-devel\ / / pcre language tool > zlib-devel / / compressed function Library
Step 4: create program users and configure Nginx service-related components
[root@localhost opt] # useradd-M-s / sbin/nologin nginx// Creator user nginx And limit its non-login terminal [root@localhost opt] # cd nginx-1.12.0/ [root@localhost nginx-1.12.0] #. / configure\ / configure nginx >-- prefix=/usr/local/nginx\ / / specify installation path >-- user=nginx\ / / specify user name >-- group=nginx\ / / specify the group to which the user belongs >-- with- Http_stub_status_module// installation status Statistics Module
Step 5: compile and install Nginx
[root@localhost nginx-1.12.0] # make & & make install
Step 6: optimize the Nginx service startup script and establish a command soft connection
[root@localhost nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ create nginx service command soft link to system command [root@localhost nginx-1.12.0] # systemctl stop firewalld.service / / turn off firewall [root@localhost nginx-1.12.0] # setenforce 0bat / turn off enhanced security function [root@localhost nginx-1.12.0] # nginx/ / input Nginx enables the service [root@localhost nginx-1.12.0] # netstat-ntap | grep 80 / / View port 80 of the service Shows that tcp 0 0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 01. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. master * LISTEN 7520/nginx:
Step 7: systemctl manages the nginx script
[root@localhost ~] # vim / lib/systemd/system/nginx.service # # create a profile [Unit] Description=nginx # # describe After=network.target # # describe the service type [Service] Type=forking # # background running form PIDFile=/usr/local/nginx/logs/nginx.pid # # PID file location ExecStart=/usr/local/nginx/sbin/nginx # # start the service ExecReload=/usr/bin/kill-s HUP $MAINPID # # configure ExecStop=/usr/bin/kill-s QUIT $MAINPID # # according to PID overload to terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root@localhost ~] # chmod according to PID 754 / lib/systemd/system/nginx.service # # set execution permission [root@localhost ~] # systemctl stop nginx.service # # close nginx [root@localhost ~] # systemctl start nginx.service # # enable nginx II. Modify Nginx.conf file [root@localhost ~] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim nginx.confgzip on # use x key to delete the hash note gzip_min_length 1k cross # compression threshold gzip_buffers 4 16k switch buffers size is 4 16k buffer size gzip _ http_version 1.1 candidate buffers # compression version number gzip_comp_level 6 x compression ratio, minimum 1, fast processing but slow transmission; maximum 9, slow processing but fast transmission Set 6 here, which is relatively moderate to the type format type gzip_disable "MSIE [1-6]\. Supported by gzip_types text/plain application/x-javascript text/css image/jpg image/jpegimage/png image/gif application/xml text/javascript application/x-httpd-php application/javascript application/json;#; # configuration disables gzip conditions and supports regular expressions, which means that gzipgzip_vary on is not enabled below ie6 # Let the front-end cache server cache gzip-compressed pages. 3. Put pictures in Nginx web pages
Step 1: copy the picture to the site directory
[root@localhost conf] # cd.. / html/ [root@localhost html] # cp / abc/game.jpg. / [root@localhost html] # ls50x.html game.jpg index.html
Step 2: modify the content of the home page of the site
[root@localhost html] # vim index.htmlWelcome to nginx!
# # add an image path under the H2 tag [root@localhost html] # systemctl stop nginx.service [root@localhost html] # systemctl start nginx.service [root@localhost html] # systemctl stop firewalld.service [root@localhost html] # setenforce 0 step 4: open a Win10 virtual machine to verify web image compression
Install the fiddler.exe package grab software in the client and open a browser to visit the 192.168.235.158 web page
Step 1: install and configure the DNS domain name resolution service [root@localhost ~] # yum install bind-y [root@localhost ~] # vim / etc/named.conf options {listen-on port 53 {any;};... Allow-query {any;}; [root@localhost ~] # vim / etc/named.rfc1912.zoneszone "accp.com" IN {type master; file "accp.com.zone"; allow-update {none;};} [root@localhost ~] # cd / var/named/ [root@localhost named] # cp-p named.localhost accp.com.zone# copy template file [root@localhost named] # vim accp.com.zone $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.235.158#IP address points to the local address [root@localhost named] # systemctl start named [root@localhost named] # systemctl stop firewalld.service [root@localhost named] # setenforce 0 step 2: open a Win7 virtual machine and build a hotlink website
1. Create a web page content and change the suffix to index.html
Cloud computing this is test web
two。 Set up a website
3. Modify the preferred DNS server address
Step 3: visit the original web page and the pirated web page respectively
Step 4: modify the Nginx.conf file [root@localhost named] # vim / usr/local/nginx/conf/nginx.conflocation ~ *\. (jpg | gif | swf) ${# supports format valid_referers none blocked * .accp.com accp.com # allow access to if with accp.com suffix ($invalid_referer) {# to determine whether rewrite ^ / http://www.accp.com/error.png; has been hacked # Jump error picture when determining if a link has been stolen}} [root@localhost named] # cp / abc/error.png / usr/local/nginx/html/ [root@localhost named] # systemctl stop nginx [root@localhost named] # systemctl start nginx step 5: visit the hotlink page here to verify the anti-theft effect
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.