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

WBOY
Release: 2023-05-12 11:58:05
forward
1012 people have browsed it

1. Install dependency packages

yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
Copy after login

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
Copy after login

3. Unzip and install

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

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
Copy after login

5. Start nginx service

cd /usr/local/nginx/sbin
./nginx
Copy after login

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
Copy after login

7. Add nginx service

vi
Copy after login

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
Copy after login

8. Start nginx as a service

pkill nginx
systemctl start nginx
Copy after login

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.
Copy after login
[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master p
Copy after login

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.
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!