Centos7编译安装nginx1.16

1. 安装依赖包

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

2. 下载安装包

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

3. 解压并安装

tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx	#安装目录
make && make install

4. 查看是否安装成功

[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. 启动服务

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

6. 查看服务启动是否成功

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

7. 添加nginx服务

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

8. 以服务的方式启动nginx

pkill nginx
systemctl start nginx

9. 查看服务是否启动

[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. 设置自启动nginx服务

[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.
发布了10 篇原创文章 · 获赞 6 · 访问量 569

猜你喜欢

转载自blog.csdn.net/J_031591/article/details/104019687