一、安装依赖包
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
依赖包说明:
1、编译依赖 gcc 环境,所以需要:gcc gcc-c++;
2、PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。Nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库,所以需要:pcre pcre-devel ;
3、zlib 库提供了很多种压缩和解压缩的方式, Nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库,所以需要:zlib zlib-devel ;
4、OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。Nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库,所以需要:openssl openssl-devel ;
二、从官网下载安装包
wget https://Nginx.org/download/Nginx-1.16.0.tar.gz
三、解压并安装
tar zxvf Nginx-1.16.0.tar.gz
cd Nginx-1.16.0
./configure --prefix=/usr/local/Nginx
make && make install
四、测试安装是否成功
[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
五、启动Nginx服务
cd /usr/local/Nginx/sbin
./Nginx
六、验证服务是否启动成功
[root@localhost sbin]# netstat -ntlp | grep Nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 349/Nginx: master
vi /lib/systemd/system/Nginx.service
将以下内容插入:
[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
八、以服务的方式启动Nginx
pkill Nginx systemctl start Nginx
九、查看服务是否启动
[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
[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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。