nginx source code compilation and problems encountered during source code compilation

This article mainly talks about nginx installation and the problems encountered during the installation process.

Talking about nginx must talk about its origin and development.

Nginx is a free and open source web server software developed by Russian engineer Igor Sysoev. It was released in 2004 and gathers a series of advantages such as light weight, high concurrency, high performance and low consumption. Nginx is currently the second most popular web server software on the Internet after Apache.

Next, we start to install nginx. We will build on centos7 as the basic environment. Our installation method: 1. yum installation 2. source code installation.

1. yum installation

1  yum install nginx

 If you don't have a yum source, you need to configure the yum source:

1  vim  /etc/yum.repos.d/nginx.repo 

Fill in the following content in nginx.repo:

1 [nginx]
2 name=nginx repo
3 baseurl=http://nginx.org/packages/centos/7/x86_64/
4 gpgcheck=0
5 enabled=1

Then we clear the cache of yum and install it

yum clean all
yum makecahe
yum install nginx

 In this way, we have successfully installed nginx. Next, we will talk about source code installation, which can be customized.

Second, the source code installation

First we need to download the source package:

Source package download address: http://nginx.org/en/download.html, we choose the stable version of the package to download

Then we unzip and install:

wget   http://nginx.org/download/nginx-1.14.0.tar.gz
tar -xzvf nginx-1.14.0.tar.gz 
cd nginx-1.14.0

Create nginx user and user group

useradd -M -s /sbin/nologin nginx

 Some general configuration options we need before proceeding with the installation:

--prefix=<path> The root path of the nginx installation, all other installation paths depend on this option
--sbin-path=<path> Specifies the path to the nginx binary. If not specified, the path will depend on the --prefix option
--conf-path=<path> If no configuration file is specified on the command line, the path specified here will be passed, and nginx will go there to find its configuration file. The path here should be accurate to the file.
--error-log-path=<path> Specifies the path to the error log file, to the exact file.
--pid-path=<path> specifies the path to the pid file, usually under /var/run/
--lock-path=<path>path to mutex file
--user=<user> The user the worker process runs as
--group=<group> The group in which the worker process runs

 These are some configuration options for custom installations:

The installation of source code generally consists of 3 steps: configuration (configure), compilation (make), and installation (make install). Next, we start to compile and install, and I will post the problems encountered during the installation process.

mkdir /opt/nginx &&chown nginx:nginx /opt/nginx/ 
./configure --prefix=/opt/nginx/ --sbin-path=/usr/bin/ --conf-path=/etc/nginx/nginx. conf --user=nginx --group=nginx
#--prefix=/opt/nginx/ The specified nginx installation directory is /opt/nginx
#--sbin-path=/usr/bin/ The specified path of the nginx binary file is /usr/bin
#--conf-path=/etc/nginx/nginx.conf Specifies the path to the configuration file
#--user=nginx specifies the user the process runs as
#--group=nginx specifies the user the process runs as

During the compilation process I encountered the following errors, here is a record:

First error: ./configure: error: C compiler cc is not found The gcc compiler is missing.

Workaround: Install the gcc compiler

yum -y install gcc-c++ autoconf automake

 The second error: /configure: error: the HTTP rewrite module requires the PCRE library. There is no PCRE library.

Workaround: Install PCRE

yum   -y install pcre pcre-devel

 第三个错误:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options. 缺少ssl错误。

Workaround: Install openssl

yum -y install openssl openssl-devel

 Fourth error: ./configure: error: the HTTP gzip module requires the zlib library. The zlib library is missing

Solution: Install the zlib library

yum install -y zlib-devel

 There are also some errors that I haven't encountered, but I will make a note here, which may help later.

Error message: ./configure: error: the HTTP XSLT module requires the libxml2/libxslt libxml2 is missing

Solution: yum -y install libxml2 libxml2-dev && yum -y install libxslt-devel

错误信息:./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

Solution: http_image_filter_module is an integrated image processing module provided by nginx, which requires the support of gd-devel yum -y install gd-devel

Error message: ./configure: error: perl module ExtUtils::Embed is required ExtUtils is missing

Workaround: yum -y install perl-devel perl-ExtUtils-Embed

错误信息:./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library. 缺少GeoIP

Workaround: yum -y install GeoIP GeoIP-devel GeoIP-data

The above are the errors that may be encountered during the configuration process. Next, we will compile.

make -j 4

 The meaning of the -j parameter is to compile in parallel, which can improve the compilation speed in the case of multi-core

Install:

make  install 

 Then we need to change the owner and group of the directory to avoid permission problems when nginx is running

chown  -R nginx:nginx /opt/nginx/
chown -R nginx:nginx /etc/nginx/

 Check the version of nginx:

[root@test1 etc]# /usr/bin/nginx  -v
nginx version: nginx/1.14.0

 run nginx

[root@test1 etc]# /usr/bin/nginx
[root@test1 etc]# ps -ef |grep nginx
root       8984      1  0 10:56 ?        00:00:00 nginx: master process /usr/bin/nginx
nginx      8985   8984  0 10:56 ?        00:00:00 nginx: worker process
root       8987   3060  0 10:56 pts/2    00:00:00 grep --color=auto nginx

 Then we can directly access port 80 of our ip (the port needs to be open)

If you open the firewall, you can close or open port 80.

Turn off the firewall:

systemctl stop firewalld

 Open port 80:

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

 When we see this interface, it means the installation was successful:

Finally, let's talk about a few nginx commands:

Start: /usr/bin/nginx
Check if the configuration file is correct: /usr/bin/nginx -t
Reload configuration file: /usr/bin/nginx -s reload
Restart: /usr/bin/nginx -s reopen
Stop: /usr/bin/nginx -s stop

 The above is a note for installing nginx.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325009260&siteId=291194637