Home >Operation and Maintenance >Nginx >What is the method to compile and install nginx1.16.0 in centos7

What is the method to compile and install nginx1.16.0 in centos7

WBOY
WBOYforward
2023-05-12 11:58:051075browse

1. Install dependency packages

yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

Dependency package description:

1. Compilation depends on the gcc environment, so you need: gcc gcc-c;

2. PCRE (Perl Compatible Regular Expressions) is a Perl library, including a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so you need to install the pcre library on Linux. pcre-devel is a secondary development library developed using pcre, so you need: pcre pcre-devel ;

3 The zlib library provides many compression and decompression methods. nginx uses zlib to gzip the contents of the http package, so the zlib library needs to be installed on Centos, so you need: zlib zlib-devel;

4, OpenSSL It is a powerful Secure Sockets Layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides a wealth of applications for testing or other purposes. nginx not only supports http protocol, but also supports https (that is, transmitting http over ssl protocol), so you need to install the OpenSSL library on Centos, so you need: openssl openssl-devel;

2. Download the installation package from the official website

wget https://nginx.org/download/nginx-1.16.0.tar.gz

3. Unzip and install

tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install

4. Test whether the installation is successful

[root@localhost ~]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --prefix=/usr/local/nginx

5. Start nginx service

cd /usr/local/nginx/sbin
./nginx

6. Verify whether the service is started successfully

[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master

7. Add nginx service

vi

Insert the following content:

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

8. Start nginx as a service

pkill nginx
systemctl start nginx

9. View the service Whether to start

[root@localhost sbin]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-04-29 23:19:39 EDT; 18min ago
  Process: 348 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 349 (nginx)
    Tasks: 2
   Memory: 976.0K
   CGroup: /system.slice/nginx.service
           ├─349 nginx: master process /usr/local/nginx/sbin/nginx
           └─350 nginx: worker process

Apr 29 23:19:39 localhost.localdomain systemd[1]: Starting nginx...
Apr 29 23:19:39 localhost.localdomain systemd[1]: Started nginx.
[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master p

10. Configure nginx service to start automatically

[root@localhost sbin]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

The above is the detailed content of What is the method to compile and install nginx1.16.0 in centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete