A- A+

Compile and use nginx under Linux series (centos, debian, etc.) systems

This article was last updated on April 20, 2019 cloud computing

Zhang Ziran kindly reminded that when compiling under small memory vps or low performance embedded devices, it is recommended to copy and execute commands line by line. Although the execution of multi line replication will be automatically segmented, it may still cause vps to be suspended (possibly due to network and other reasons).

Install the compilation environment required for configuring nginx or modules.

Installation and compilation environment of ububtu/debian related systems

apt-get -y install build-essential libtool

Red hat/Centos related system installation and compilation environment

yum -y install automake autoconf libtool make gcc gcc-c++

Common nginx modules

The following modules are selected as needed, and the corresponding nginx configuration is modified.

New nginx related source code storage directory

It is used to store various source codes to prevent confusion and facilitate repeated compilation in the future.

mkdir /root/nginx/

Download the source code of pcre (url rewriting module) and pre configure it

Official website of pcre url rewriting module: http://www.pcre.org/

wget  https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz (20170503 latest version)

wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.zip (20160910 latest version)

wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz

unzip pcre*

tar zxvf pcre*

cd pcre*

./configure

Download zlib (gzip compression module) source code and pre configure

Official website of zlib gzip compression module: http://www.zlib.net/

20170106 Inspection official updated zlib 1.2.10 in January 2, 2017

20160910, the latest version was checked and updated on April 28, 2013

wget http://www.zlib.net/zlib-1.2.11.tar.gz

wget  http://www.zlib.net/zlib1210.zip

wget  http://zlib.net/zlib-1.2.8.tar.gz

unzip zlib*

tar zxvf zlib*

cd zlib*

./configure

Download the openssl ssl module source code

Official website of openssl ssl module: http://www.openssl.org/

20170106 Check and update

20160910 Update openssl-1.0.2h

wget  https://www.openssl.org/source/openssl-1.0.2k.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz

wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz

wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz

tar zxvf openssl*

Download the source code of ngx_http_substitutions_filter_module (nginx reverse proxy replacement module)

Ngx_http_substitutions_filter_module Reverse proxy replacement module Author github:

https://github.com/yaoweibin/ngx_http_substitutions_filter_module

--No check certificate means that wget does not check the website certificate.

Updated 20160910

wget  https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip  --no-check-certificate

apt-get install unzip -y

unzip master*

mv ngx_http_substitutions_filter_module-master ngx_http_substitutions_filter_module

Then you will see the ngx_http_substitutions_filter_module directory for future use.

Download the ngx_cache_purge-2.3 cache module source code

NGx_cache_purge-2.3 Cache module homepage: http://labs.frickle.com/nginx_ngx_cache_purge

Updated 20160910

wget  http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

tar -zxvf ngx_cache_purge*

Download the source code of the cloud lock (nginx security protection) module

cd /root/nginx

wget https://codeload.github.com/yunsuo-open/nginx-plugin/zip/master -O nginx-yunsuo.zip

Install the cloud lock server

wget https://download.yunsuo.com.cn/v3/yunsuo_agent_64bit.tar.gz && tar xvzf yunsuo_agent_64bit.tar.gz && chmod +x yunsuo_install/install && yunsuo_install/install

 

Compile and install nginx

Download the source code of nginx main program

Nginx official website: http://nginx.org/

wget  http://nginx.org/download/nginx-1.11.8.tar.gz

wget http://nginx.org/download/nginx-1.11.3.tar.gz

wget http://nginx.org/download/nginx-1.8.0.tar.gz

wget http://nginx.org/download/nginx-1.9.9.tar.gz

wget http://nginx.org/download/nginx-1.7.9.tar.gz

tar zxvf nginx*

cd nginx*

./configure --user=zhttpd --group=zhttpd --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/l ib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-http_ssl_module --with-http_v2_module --with-pcre=/root/nginx/pcre-8.40/ --with-zlib=/root/nginx/zlib-1.2.11 --with-openssl=/root/nginx/openssl-1.0.2k --add-module=/root/nginx/ngx_http_substitutions_filter_module/

 

 

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy- temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --w ith-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module - -with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -fPIC' --with-ld-opt='-Wl,-z, relro -Wl,-z,now -pie' --with-pcre=/root/nginx/pcre-8.40/ --with-zlib=/root/nginx/zlib-1.2.11 --add-module=/root/nginx/ngx_http_substitutions_filter_module/ --with-openssl=/root/nginx/openssl-1.0.2k --add-module=/root/nginx/nginx-yunsuo

 

 

--add-module=/root/nginx/nginx-yunsuo

make && make install

If the version is lower than 1.95, please change the -- with-http_v2_module to -- with-http_spdy_module and recompile it to pass See below for details)

--With pcre=/root/nginx/pcre-8.36/refers to the source code path of pcre-8.36.

--With zlib=/root/nginx/zlib-1.2.8/refers to the source code path of zlib-1.2.8.

--With openssl=/root/nginx/openssl-1.0.1k refers to the source code path of openssl-1.0.1k.

--Add module=/root/nginx/ngx_http_substitutions_filter_module/refers to the source code path of ngx_http_substitutions_filter_module.

Back up nginx and upgrade it.

If you already have nginx, just execute make, and make install will overwrite your nginx. conf

For nginx versions above 1.8.0, add - DHIGHERTHAN8 after the first line of the objs/Makefile file in the nginx directory. If it is tengine, it does not need to be modified. If it is an old version of nginx, see the Yunsuo official website: http://help.yunsuo.com.cn/instruction/Nginx/install.html

The appearance after adding

CC = cc
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DHIGHERTHAN8
CPP = cc -E
LINK = $(CC)

Create nginx users and groups. ID www is to determine whether the uid and gid of the www account and the user name of the group are correct

groupadd -r zhttpd

useradd -s /sbin/nologin -g zhttpd -r zhttpd

id zhttpd

Create a new/var/lib/nginx directory

Otherwise, nginx: [emergency] mkdir() "/var/lib/nginx/body" failed (2: No such file or directory) error will be reported

mkdir /var/lib/nginx

Copy compiled nginx

cp ./objs/nginx /usr/sbin/

start nginx

/usr/sbin/nginx

Back up nginx binary files (skip this step for new installation)

cp /usr/sbin/nginx /usr/sbin/nginx.bak

Stop nginx (It doesn't matter if you stop for a few seconds at a small station, and you don't need to read the tutorial at a large station.)

service nginx stop

Upgrade nginx binaries:

cp ./objs/nginx /usr/sbin/

Pagoda installation custom module

https://www.bt.cn/bbs/thread-16118-1-1.html

Modify nginx installation script to add compiled modules

/www/server/panel/install/nginx.sh

--add-module=/root/nginx/ngx_http_substitutions_filter_module/ --add-module=/root/nginx/nginx-yunsuo

Execute the script to start compiling and installing nginx

If you are prompted that you do not have permission, first turn off the pagoda, cloud lock and other system hardening functions.

1.15 Representative version number

sh /www/server/panel/install/nginx.sh install 1.15

Nginx adds the following information

Proxy_cache_path/home/cache/path levels=1:2 keys_zone=c_1: 18m inactive=7d max_size=1g; # 5m is the memory occupation, 1g is the maximum hard disk occupation, and c_1 is the cache name. If you modify it, the following configuration should also be modified accordingly.
include /www/server/panel/vhost/nginx/*.conf;
include /www/server/panel/vhost/nginx/google/*.conf;
include /www/server/panel/vhost/nginx/other/*.conf;

 

tar: Old option `f' requires an argument.

Add or delete when prompted-

tar -zxvf ngx_cache_purge*

 

label:

  1. Long time companion blog
    It was written in great detail
  2. repostone
    pass by.

Leave a message to Zhang Ziran's personal blog