Centos7 source code compilation and installation of Nginx1.13

  • 2020-05-14 06:05:51
  • OfStack

I won't say anything about nginx. Since you have chosen nginx as your web server, you must have a different understanding of nginx server, so I will install it directly.

1. Prerequisites:

I used centos7.3 64-bit core version of the system. Before installing and configuring nginx, you must install the nginx dependency package. Please check. Centos 7 builds the production installment php 7.1 and installs the dependencies provided at the beginning of the previous section. This dependency package applies to any version of Nginx.

Create a new web user and group


$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
$ ulimit -SHn 65535 // Set up the linux High load parameter 

2. Download Nginx and OpenSSL from the official website

Download Nginx has two versions: development and stable version, if used in the production of stable version download, http: / / nginx org/en/download html (best to download the latest version of the stable version, so there will be a bug repair as well as new features) I download is currently the latest version is nginx - 1.13.5.


$ cd /tmp
$ wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
$ tar zxvf openssl-1.1.0e.tar.gz
$ wget https://nginx.org/download/nginx-1.13.5.tar.gz
$ tar zxvf nginx-1.13.5.tar.gz
$ cd nginx-1.13.5

3. Install Nginx

You may notice some document tutorial nginx installation, does not assign so many modules, (long) look, some even not assigned module and user, actually module is assigned according to their needs, if you want to later not trouble, then according to the following modules assigned to go, actually this is the almighty, late or what do you need have to recompile, not very troublesome, but it's not convenient. As for whether or not to assign user groups, I will definitely let you do so, as this is related to the availability and security stability of the nginx configuration.


$ ./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre \
--with-openssl=/tmp/openssl-1.1.0e \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module \

$ make -j8 && make install // Compile and install 

4. Create systemctl system Nginx cell files

After the installation is completed, it is necessary to boot the machine and start it from scratch. Otherwise, it would be too troublesome to manually boot the machine every time.


$ vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Save and exit.

5. Start the machine and start Nginx


$ systemctl enable nginx.service
$ systemctl restart nginx.service

6. Set Firewalld firewall


$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload

7. Check if Nginx started successfully


$ ss -ntlp

You can see that the nginx process is already running. Now the installation of nginx is finished. You may have some questions about how nginx can parse and support the php program. Don't panic, I will write about it in the next article.


Related articles: