We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
[HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
[HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
Introduction
PageSpeed is one of the Nginx’s modules developed by Google to speed up the web site or web applications response time, it can automatically optimize the returned HTML to reduce the page load time. PageSpeed has the ability of image optimization using stripping meta-data, dynamic resizing and recompression.
Some of the main benefits of PageSpeed are listed below:
Install Dependencies
First of all, we need to install some dependencies because we are going to compile Nginx from the source, so execute the following command to install all of the needed dependencies:
Download and compile Nginx with Ngx_pagespeed
To install Nginx with “pagespeed” module you need to compile Nginx from the source but first, you have to download it using the following command:
Then download the Ngx_pagespeed source as well:
Now that both needed sources are downloaded, extract them with the commands below:
You will also need to download the PageSpeed Optimization Libraries to compile Nginx, execute the commands below one by one to get it download and extract it in the preferred route:
Now we can start compiling Nginx with Ngx_pagespeed module.
First switch to the main directory of the Nginx’s source:
Run the following command to start compiling it:
Once the configuration is completed, compile the Nginx by the following command:
The process will take a few minutes.
When the installation process is finished you have to create Nginx symlinks:
Create Nginx Systemd service
You will need to create a systemd service for Nginx in order to “start, stop and make your service run as startup.
Create a file named “nginx.service” with your text editor in the following path:
Paste the following lines in the file then save and exit:
Run the following command to take effect:
Now you can start your Nginx and make it run as a startup service:
Configure Nginx
Now, Nginx is installed and has the PageSpeed support, but the module is disabled by default but before enabling it we need to create a cache directory for PageSpeed and also assign ownership for it to Nginx.
Next, you need to add some lines in the Nginx configuration. Open the “nginx.conf” with your text editor using the command below:
Add the following lines in the “server” directive:
Test your configuration with the command below:
You should see the following output:
Restart Nginx service to take effect:
Test if PageSpeed is working
You can easily test your PageSpeed module using “curl” command:
You should see the red line in your output:
PageSpeed is one of the Nginx’s modules developed by Google to speed up the web site or web applications response time, it can automatically optimize the returned HTML to reduce the page load time. PageSpeed has the ability of image optimization using stripping meta-data, dynamic resizing and recompression.
Some of the main benefits of PageSpeed are listed below:
- CSS & JavaScript minification, concatenation, inlining, and outlining.
- Small resource inlining.
- HTML rewriting.
- Cache lifetime extension.
Install Dependencies
First of all, we need to install some dependencies because we are going to compile Nginx from the source, so execute the following command to install all of the needed dependencies:
Code: Select all
yum install gcc cmake unzip wget gcc-c++ pcre-devel zlib-devel
To install Nginx with “pagespeed” module you need to compile Nginx from the source but first, you have to download it using the following command:
Code: Select all
wget http://nginx.org/download/nginx-1.12.0.tar.gz
Code: Select all
wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.12.34.2-stable.zip
Code: Select all
tar xvzf nginx-1.12.0.tar.gz
unzip v1.12.34.2-stable.zip
Code: Select all
cd ngx_pagespeed-1.12.34.2-stable
wget https://dl.google.com/dl/page-speed/psol/1.12.34.2-x64.tar.gz
tar -xvzf 1.12.34.2-x64.tar.gz
First switch to the main directory of the Nginx’s source:
Code: Select all
cd ~/nginx-1.12.0
Code: Select all
./configure --add-module=$HOME/ngx_pagespeed-1.12.34.2-stable --user=nobody --group=nobody --pid-path=/var/run/nginx.pid
Code: Select all
make && make install
When the installation process is finished you have to create Nginx symlinks:
Code: Select all
ln -s /usr/local/nginx/conf/ /etc/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
You will need to create a systemd service for Nginx in order to “start, stop and make your service run as startup.
Create a file named “nginx.service” with your text editor in the following path:
Code: Select all
nano /lib/systemd/system/nginx.service
Code: Select all
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Code: Select all
systemctl daemon-reload
Code: Select all
systemctl start nginx
systemctl enable nginx
Now, Nginx is installed and has the PageSpeed support, but the module is disabled by default but before enabling it we need to create a cache directory for PageSpeed and also assign ownership for it to Nginx.
Code: Select all
mkdir -p /var/ngx_pagespeed_cache
chown -R nobody:nobody /var/ngx_pagespeed_cache
Code: Select all
nano /etc/nginx/nginx.conf
Code: Select all
# Pagespeed main settings
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed
# handler and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
Code: Select all
nginx -t
Code: Select all
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Code: Select all
systemctl restart nginx
You can easily test your PageSpeed module using “curl” command:
Code: Select all
curl -I -p localhost
Code: Select all
HTTP/1.1 200 OK
Server: nginx/1.12.0
Content-Type: text/html
Connection: keep-alive
Vary: Accept-Encoding
Date: Sat, 22 Jul 2017 11:17:53 GMT
X-Page-Speed: 1.12.34.2-0
Cache-Control: max-age=0, no-cache
Re: [HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
Why not use rpmbuild?
-
- Support team
- Posts: 1111
- Joined: Tue Jul 30, 2013 10:18 pm
- Contact:
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: [HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
More simplest way:
https://www.modpagespeed.com/doc/build_ ... rom_source
:)
Code: Select all
bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version latest
:)
-
- Posts: 5
- Joined: Wed Jan 09, 2019 12:16 pm
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: [HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
Hi!
I was following step by step. On "make && make install" command I got this:
make: *** No rule to make target `build', needed by `default'. Stop.
Any idea what does it mean?
Thanks!
I was following step by step. On "make && make install" command I got this:
make: *** No rule to make target `build', needed by `default'. Stop.
Any idea what does it mean?
Thanks!
-
- Posts: 5
- Joined: Wed Jan 09, 2019 12:16 pm
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: [HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
I got it! The name of the folder extracted was wrong. The correct were "incubator-pagespeed-ngx-1.12.34.2-stable". So, the command is thismaxmedeiros wrote: ↑Fri Feb 08, 2019 2:18 pmHi!
I was following step by step. On "make && make install" command I got this:
make: *** No rule to make target `build', needed by `default'. Stop.
Any idea what does it mean?
Thanks!
Code: Select all
./configure --add-module=$HOME/incubator-pagespeed-ngx-1.12.34.2-stable --user=nobody --group=nobody --pid-path=/var/run/nginx.pid
-
- Posts: 5
- Joined: Wed Jan 09, 2019 12:16 pm
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: [HowTo] install Nginx with Google PageSpeed module (ngx_pagespeed) on CentOS 7
When I run "nginx -t" I got this
nginx: [emerg] unknown directive "pagespeed" in /etc/nginx/nginx.conf:135
nginx: configuration file /etc/nginx/nginx.conf test failed
Where exactly, in nginx.conf, I have to put this code:
Bellow witch line?
Thanks!
nginx: [emerg] unknown directive "pagespeed" in /etc/nginx/nginx.conf:135
nginx: configuration file /etc/nginx/nginx.conf test failed
Where exactly, in nginx.conf, I have to put this code:
Code: Select all
# Pagespeed main settings
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed
# handler and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
Thanks!