Installation and compilation platform
The Ubuntu platform compilation environment can use the following instructions
apt-get install build-essential apt-get install libtool
centos uses the following
yum -y install gcc automake autoconf libtool make
Install g + +:
yum install gcc gcc-c++
Generally, we need to install PCRE and zlib first. The former is for rewriting and rewriting, and the latter is for gzip compression.
It can be any directory, and / usr/local/src is selected in this article
Install PCRE Library
https://ftp.pcre.org/pub/pcre/ Download the latest PCRE source package, and use the following command to download, compile and install the PCRE package:
cd /usr/local/src wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz tar -zxvf pcre-8.44.tar.gz cd pcre-8.44 ./configure make make install
Install zlib Library
http://zlib.net/zlib-1.2.11.tar.gz Download the latest zlib source package, and use the following command to download, compile and install the zlib package:
cd /usr/local/src wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install
Install ssl (some vps do not install ssl by default)
cd /usr/local/src wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz tar -zxvf openssl-1.1.1g.tar.gz
There are generally two versions of Nginx, the stable version and the development version. You can choose one of these two versions according to your purpose. The official website address is: http://nginx.org/en/download.html , the following are the detailed steps to install Nginx into the / usr/local/nginx Directory:
cd /usr/local/src wget http://nginx.org/download/nginx-1.21.5.tar.gz tar -zxvf nginx-1.21.5.tar.gz cd nginx-1.21.5 ./configure --sbin-path=/usr/local/nginx/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-file-aio \ --with-http_realip_module \ --with-http_ssl_module \ --with-pcre=/usr/local/src/pcre-8.44 \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-openssl=/usr/local/src/openssl-1.1.1g make -j2 make install
– with PCRE = / usr / local / SRC / pcre-8.44 refers to the source code path of pcre-8.44.
– with zlib = / usr / local / SRC / zlib-1.2.11 refers to the source code path of zlib-1.2.11.
Make sure that port 80 of the system is not occupied by other programs. Run the / usr/local/nginx/nginx command to start Nginx,
netstat -ano|grep 80
If the result cannot be found, execute it. If there is a result, ignore this step (sudo must be used to start under ubuntu, otherwise it can only be run in the foreground)
sudo /usr/local/nginx/nginx -s reload
sudo /usr/local/nginx/nginx -s stop
View nginx status
ps -ef|grep nginx
At this point, the installation of nginx is completed. If you only process static html, you don't need to continue the installation
If you need to handle php scripts, you also need to install php-fpm.
Attachment: possible errors and some help information
1.1 pcre compilation error
libtool: compile: unrecognized option `-DHAVE_CONFIG_H' libtool: compile: Try `libtool --help' for more information. make: *** [pcrecpp.lo] Error 1 make: Leaving directory `/usr/local/src/pcre-8.34' make: *** [all] Error 2
Solution: install g + +, and don't forget to reconfigure
apt-get install g++ apt-get install build-essential make clean ./configure make
1.2 make error
make: *** No rule to make target `build', needed by `default'. Stop. ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl= option.
yum -y install openssl openssl-devel
apt-get install openssl apt-get install libssl-dev
2.nginx compilation options
make is used to compile. It reads instructions from Makefile and then compiles.
make install is used for installation. It also reads instructions from Makefile and installs them to the specified location.
The configure command is used to detect the target characteristics of your installation platform. It defines all aspects of the system, including the allowed connection processing methods of nginx. For example, it will detect whether you have CC or GCC and do not need CC or GCC. It is a shell script. At the end of execution, it will create a Makefile file. The configure command of nginx supports the following parameters:
- – prefix=path defines a directory to store files on the server, that is, the installation directory of nginx. The default is / usr/local/nginx.
- – SBIN path = path sets the path of the executable file of nginx. The default is prefix/sbin/nginx
- – conf path = path set in nginx Path to the conf configuration file. Nginx allows you to start with different configuration files, using the - c option on the command line. The default is prefix / conf / nginx conf
- – PID path = path set nginx PID file, which will store the process number of the main process. After installation, you can change the file name at any time in nginx The PID instruction is used in the conf configuration file. By default, the file name is prefix / logs / nginx pid.
- – error log path = path sets the name of the main error, warning, and diagnostic files. After installation, you can change the file name at any time in nginx Error used in conf configuration file_ Log instruction. By default, the file name is prefix / logs / error log.
- – HTTP log path = path sets the name of the log file of the HTTP server for the main request. After installation, you can change the file name at any time in nginx Access used in conf configuration file_ Log instruction. By default, the file name is prefix / logs / access log.
- – user=name sets the user of the nginx worker process. After installation, you can change the name at any time in nginx The user directive used in the conf configuration file. The default user name is nobody.
- – group=name sets the user group of the nginx worker process. After installation, you can change the name at any time in nginx The user directive used in the conf configuration file. The default is a non privileged user.
- –with-select_module --without-select_module enables or disables building a module to allow the server to use the select() method. The module will be established automatically if the platform does not support kqueue, epoll, rtsig or / dev/poll.
- –with-poll_module --without-poll_module enables or disables building a module to allow the server to use the poll() method. The module will be established automatically if the platform does not support kqueue, epoll, rtsig or / dev/poll.
- –without-http_gzip_module - the response module of the compressed HTTP server is not compiled. The zlib library is required to compile and run this module.
- –without-http_rewrite_module does not compile or rewrite modules. PCRE library support is required to compile and run this module.
- –without-http_proxy_module - do not compile http_proxy module.
- –with-http_ssl_module - use https protocol module. By default, the module is not built. It is necessary to establish and run the OpenSSL Library of this module.
- – with PCRE = path - sets the source path of the PCRE library. The source code of PCRE Library (version 4.4 - 8.30) needs to be downloaded and unzipped from PCRE website. The rest of the work is Nginx's/ configure and make. Regular expressions are used in the location instruction and ngx_http_rewrite_module module.
- – with PCRE JIT -- compiling PCRE includes "just in time compilation" (pcre_jit instruction in 1.1.12).
- – with zlib = path - set the source path of the zlib library. To download from zlib (version 1.1.3 - 1.2.5) and unzip. The rest of the work is Nginx's/ configure and make are complete. ngx_http_gzip_module module requires zlib.
- – with CC opt = parameters - setting additional parameters will be added to the CFLAGS variable. For example, when using the PCRE library on FreeBSD, you need to use: – with CC opt = "- I / usr / local / include". If necessary, increase the number of files supported by select(): – with CC opt = "- D FD_ SETSIZE=2048".
- – with LD opt = parameters - sets additional parameters that will be used during linking. For example, when using the PCRE Library of the system under FreeBSD, you should specify: – with LD opt = "- L / usr / local / lib"