Practice configuring LNMP environment with ngx

888u

Last update at :2024-06-22,Edit by888u

Maybe many friends are like snails. When browsing some websites, when they see good JS special effects and pictures, they like to bookmark the functions or save the pictures as downloads. I often see strange suffixes when downloading JS and images. For example, with a suffix like ".jpg.pagespeed.ic.TyXVh2L5XY.jpg\\", you can see that the ngx_pagespeed acceleration plug-in is installed in the current website environment. . Therefore, in this article, Snail will also see how to install ngx_pagespeed in the Linux VPS host WEB environment. You may not necessarily use it, but you will see how to install it.

From a user experience perspective, JS and image addresses like this don’t look good, but some large websites also use them, which should speed things up to a certain extent. It is said that the performance of single-core machines is not ideal, and the resources occupied are relatively large.

First, prepare to install ngx_pagespeed

1. This test environment uses Junge LNMP V1.3 version environment. By default, ngx_pagespeed is not installed or can be quickly installed.

2. Back up data. It is recommended that we test in the test machine environment first, and then use the production environment if necessary. Do not use the production environment directly, because Nginx needs to be recompiled and upgraded in case something goes wrong.

Second, download the ngx_pagespeed plug-in

wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.9.32.10-beta.zipunzip v1.9.32.10-beta.zipcd ngx_pagespeed-1.9.32.10-betawget https://dl.google .com/dl/page-speed/psol/1.9.32.10.tar.gztar -xzvf 1.9.32.10.tar.gz

Here we need to download the ngx_pagespeed and psol optimization libraries. The latest version is v1.9.32.10. Specifically, we can see the current version at https://github.com/pagespeed/ngx_pagespeed/releases.

Third, modify the upgrade file

Here we need to recompile Nginx. LNMP does not provide one-click quick installation of ngx_pagespeed. Here we add it to Nginx and then upgrade and specify the compilation.

Find upgrade_nginx.sh in lnmp1.3-full/include, and add \\" at the end of the location \\"./configure –user=www –group=www –prefix=/usr/local/nginx\\" –add-module=$HOME/ngx_pagespeed-1.9.32.10-beta\\”

./upgrade.sh

Then execute the command to upgrade Nginx.

Select 1 here, and then you also need to select the Nginx version.

Fourth, site startup ngx_pagespeed

# Enable ngx_pagespeedpagespeed on;pagespeed FileCachePath /tmp/cache/ngx_pagespeed_cache;# Disable CoreFilterspagespeed RewriteLevel PassThrough;# Enable compression whitespace filter pagespeed EnableFilters collapse_whitespace;# Enable JavaScript library unloading pagespeed EnableFilters canonicalize_javascript_libraries; #Google is blocked, not sure Does this setting have any side effects?# Combine multiple CSS files into one CSS file pagespeed EnableFilters combine_css;# Combine multiple JavaScript files into one JavaScript file pagespeed EnableFilters combine_javascript;# Delete tags with default attributes pagespeed EnableFilters elide_attributes;# Improve resources Cacheability pagespeed EnableFilters extend_cache;# Replace the @import of the imported file and simplify the CSS file pagespeed EnableFilters flatten_css_imports;pagespeed CssFlattenMaxBytes 5120;# Delay loading of images invisible to the client pagespeed EnableFilters lazyload_images;# Enable JavaScript reduction mechanism pagespeed EnableFilters rewrite_javascript; # Enable image optimization mechanism pagespeed EnableFilters rewrite_images; # Pre-parse DNS query pagespeed EnableFilters insert_dns_prefetch; # Rewrite CSS, first load the CSS rules of the rendered page pagespeed EnableFilters prioritize_critical_css; # Example disable pagespeed processing /wp-admin/ directory (optional configuration, Please refer to) pagespeed Disallow \\”*/wp-admin/*\\”;

Throw the above configuration file into the nginx configuration file server that currently needs to start the ngx_pagespeed site. Specific remarks can be seen. The above paragraph refers to Zhang Ge (https://zhangge.net/5063.html).

At the same time, a buffer directory needs to be created

mkdir -p /tmp/cache/ngx_pagespeed_cache

Fifth, restart Nginx to take effect

service nginx restart

Restarting Nginx will take effect. Then go to the snail to install the WORDPRESS test website to see if the source code has changed.

You can see that it has taken effect.

Finally, in this article, the LNMP environment can be implemented, including other Nginx, which is almost the same. You can install ngx_pagespeed, but it is better not to use it for low-configuration machines or those who are entangled with ugly suffixes in file names.

Recommended site search: independent IP virtual host, domain name fast registration, server hosting IDC, Ministry of Information Industry registration, Wanwang domain name registration official website, domain name batch query, website space domain name, multi-IP station group server, Hong Kong domain name registration, cheap Virtual host,

Practice configuring LNMP environment with ngx

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码