A tutorial for compiling components and modules into Nginx packages under Linux

Source: Internet
Author: User
Tags mkdir


Under the Ubuntu system, we usually use apt-get to get everything done, easy and quick. But if you want to add additional modules to the Nginx, you need to recompile. Compiling nginx from the source code will manually supplement some of the files provided by the Debian package, such as startup scripts, Logrotate, and so on.
Get the extra modules

Take Pagespeed, upload module as an example.

Get the Pagespeed module:


sudo mkdir/opt/pagespeed
Cd/opt/pagespeed
nps_version=1.9.32.2
sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${nps_version}-beta.zip
sudo unzip Release-${nps_version}-beta.zip
CD ngx_pagespeed-release-${nps_version}-beta/
sudo wget https://dl.google.com/dl/page-speed/psol/${nps_version}.tar.gz
sudo tar-xzvf ${nps_version}.tar.gz # extracts to psol/
# gives us Directory/opt/pagespeed/ngx_pagespeed-release-1.9.32.2-beta

Get the Upload module:

sudo mkdir/opt/httpupload
Cd/opt/httpupload
sudo wget https://github.com/vkholodkov/nginx-upload-module/archive/2.2.zip
sudo unzip 2.2.zip
# gives us directory:/opt/httpupload/nginx-upload-module-2.2

Get Nginx source Packages and dependencies
Add Nginx source, adjust, rebuild, and reinstall Nginx.
Add the PPA source file and make sure the DEB-SRC directive is not commented out.


$ vim/etc/apt/sources.list.d/nginx-stable-trusty.list
Deb Http://ppa.launchpad.net/nginx/stable/ubuntu Trusty Main
DEB-SRC Http://ppa.launchpad.net/nginx/stable/ubuntu Trusty Main

Update

$ sudo apt-get update

Get the source package and the dependency pack


# Install Package Creation Tools
sudo apt-get install-y Dpkg-dev

sudo mkdir/opt/rebuildnginx
Cd/opt/rebuildnginx

# get Nginx (ppa:nginx/stable) source files
sudo apt-get source Nginx

# Install The Build dependencies
sudo apt-get build-dep nginx


$ ls-lah/opt/rebuildnginx
Drwxr-xr-x root root 4096 Dec 16:37 nginx-1.6.2/
-rw-r--r--1 root 934244 Dec 02:10 nginx_1.6.2-5+trusty0.debian.tar.gz
-rw-r--r--1 root 2798 Dec 02:10 NGINX_1.6.2-5+TRUSTY0.DSC
-rw-r--r--1 root root 804164 Sep 21:31 nginx_1.6.2.orig.tar.gz
Ppa:nginx/stable offers multiple Nginx available packages: Common, light, full, extras. When the Apt-get install-y Nginx is executed, the full version is installed.

The light is less than the common--without-* option package.

Edit the/opt/rebuildnginx/nginx-1.6.2/debian/rules file to add a third-party module.


Full_configure_flags: = \
$ (common_configure_flags) \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_spdy_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--add-module=$ (modulesdir)/nginx-auth-pam \
--add-module=$ (modulesdir)/nginx-dav-ext-module \
--add-module=$ (modulesdir)/nginx-echo \
--add-module=$ (modulesdir)/nginx-upstream-fair \
--add-module=$ (modulesdir)/ngx_http_substitutions_filter_module \
--add-module=/opt/httpupload/nginx-upload-module-2.2 \
--add-module=/opt/pagespeed/ngx_pagespeed-release-1.9.32.2-beta
Rebuilding the Nginx Package

cd/opt/rebuildnginx/nginx-1.6.2
sudo dpkg-buildpackage-b

After rebuilding, a bunch of. deb files are produced in the/opt/rebuildnginx directory, which you can use to install Nginx. Because we have adjusted the ' full ' package, we need to use the package to install Nginx. The package has two:

Nginx-full-dbg_1.6.2-5+trusty0_amd64.deb
Nginx-full_1.6.2-5+trusty0_amd64.deb
DBG is the debug version.

Reinstall Nginx, you may need to remove the previously installed Nginx.

#. deb files appear one level above the ' nginx-1.6.2 ' directory
Cd/opt/rebuildnginx
sudo dpkg--install nginx-full_1.6.2-5+trusty0_amd64.deb

To view installed modules


$ nginx-v
Nginx version:nginx/1.6.2
TLS SNI Support Enabled
Configure arguments:
--with-cc-opt= '-g-o2-fstack-protector--param=ssp-buffer-size=4-wformat-werror=format-security-d_fortify_source =2 '
# A Bunch of removed for brevity
--add-module=/opt/httpupload/nginx-upload-module-2.2 # yay!
--add-module=/opt/pagespeed/ngx_pagespeed-release-1.9.32.2-beta # yay!

Configure Pagespeed

sudo mkdir-p/var/cache/ngx_pagespeed/
# Stuff up here omitted
Server {
    pagespeed on;     pagespeed Filecachepath "/var/cache/ngx_pagespeed/";
    pagespeed enablefilters combine_css,combine_javascript;
 
    # Stuff down omitted
}
$ sudo service nginx configtest
 * Testing Nginx configuration            [OK]
 
# Restart , assuming it ' s OK
$ sudo service nginx restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.