Home WebServer PanelDirectAdmin Install mod_pagespeed into Nginx on DirectAdmin

Install mod_pagespeed into Nginx on DirectAdmin

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

This tutorial will guide you through installing mod_pagespeed on Nginx in DirectAdmin servers if your Webserver is running as a reverse-proxy Nginx_Apache, which would not be applicable.

I. Introduction

Mod_pagespeed is an open-source Apache HTTP (or Nginx) Server module that automatically applies selected filters to pages and related content such as style sheets, JavaScript and HTML files, as well as images and related site cache requirements.

A key advantage of this module is that it requires no modification of existing content or workflow, which means all internal optimizations and file changes are done on the server, showing modified files directly to users accessing the website.

Note: This tutorial only applies to Nginx; if you are running Nginx_Apache, it will not apply.

II. Install mod_pagespeed into Nginx on the DirectAdmin server

To install mod_pagespeed into Nginx on the DirectAdmin server, we need to do the following 2 steps.

Step 1: SSH into your server

To install mod_pagespeed into Nginx on the DirectAdmin server, we first need to SSH or access your VPS/server with root privileges. Or at least log in to the server with a user with sudo privileges. If you don’t know how to SSH into your VPS/Server, you can refer to the following tutorial:

After successfully SSH, we continue with step 2 to execute the Install mod_pagespeed commands into Nginx.

Step 2: Commands to install mod_pagespeed into Nginx on DirectAdmin server

We will download the source code of page-speed with the following commands:

AZDIGI Tutorial
# NPS_VERSION=1.13.35.2-stable
# cd
# wget https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.zip
# unzip v${NPS_VERSION}.zip
# nps_dir=$(find . -name "*pagespeed-ngx-${NPS_VERSION}" -type d)
# cd "$nps_dir"
# NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
# NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
# psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz
# [ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
# wget ${psol_url}
# tar -xzvf $(basename ${psol_url})
    

Because the number of commands is quite large, I will add # in front for you to easily distinguish the commands.

Here are the images when I run the above commands:

Install mod_pagespeed into Nginx on DirectAdmin
Commands 1, 2, 3.
Install mod_pagespeed into Nginx on DirectAdmin
Command 4.
Screen Shot 2021 04 22 at 7.48.51 PM
Commands 5 to 11.
Install mod_pagespeed into Nginx on DirectAdmin
Command 12.

Next, we will customize the Nginx configuration file to add an external module with these 3 commands:

AZDIGI Tutorial
# cd /usr/local/directadmin/custombuild/
# mkdir -p custom/nginx
# cp configure/nginx/configure.nginx custom/nginx/
    
Install mod_pagespeed into Nginx on DirectAdmin

Once we have copied the Nginx configuration file, we use the following command to start the customization process:

AZDIGI Tutorial
# vi /usr/local/directadmin/custombuild/custom/nginx/configure.nginx
    

Below is my default configuration file:

Install mod_pagespeed into Nginx on DirectAdmin

You will need to add the content following next to the last line of this configuration:

AZDIGI Tutorial
# "--add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable" \
    

Here is the config file after I added the custom config line above:

Install mod_pagespeed into Nginx on DirectAdmin

Save and start installing Ngix again with the new configuration:

AZDIGI Tutorial
# cd /usr/local/directadmin/custombuild
# ./build update
# ./build nginx
    

After your server reinstalls Nginx, you need to create a working directory for pagespeed:

AZDIGI Tutorial
# mkdir -p /var/cache/ngx_pagespeed
    

Next, you need to add the following configuration to the /etc/nginx/nginx-includes.conf file:

AZDIGI Tutorial
pagespeed on;
pagespeed FileCachePath /var/cache/ngx_pagespeed;
pagespeed EnableFilters flatten_css_imports;
    

Finally, you just need to restart Nginx with the following command:

AZDIGI Tutorial
service nginx restart
    

You can now use the following command to check with a domain on your server:

AZDIGI Tutorial
curl -Is domain.com | grep X-Page-Speed
    

Remember to replace domain.com with a domain name running on your server. The result as shown below is complete.

AZDIGI Tutorial
X-Page-Speed: 1.13.35.2-0
    

III. Summary

After installing mod_pagespeed into Nginx on the DirectAdmin server, you can see that your website on your server works faster and your Google Page Speed score is much improved. However, if you are operating many websites under development, you should not install Mod_Pagespeed because it will cause many problems with viewing sources and HTML editing/cutting.

Reference article: How to install the Pagespeed Nginx module.

Wishing you success. See more useful articles about DirectAdmin at the following link:

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign