Cetnos7安装Nginx

所需依赖/组件

  • gcc

yum -y install gcc

  • pcre

yum install -y pcre pcre-devel

  • zlib

yum install -y zlib zlib-devel

安装Nginx

  • 下载源码包

wgt http://nginx.org/download/nginx-1.19.6.tar.gz

  • 解压

tar -zxvf nginx-1.19.6.tar.gz -C /tmp/

  • 编译&安装
cd /tmp/nginx-1.19.6/
./configure
make
make install

编译安装完成后会看到类似内容:

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
  • 启动Nginx
cd /usr/local/nginx/sbin/
./nginx
  • 将编译安装的Nginx注册为服务使用systemctl管理

vi /usr/lib/systemd/system/nginx.service

内容如下:

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]

重载系统服务
systemctl daemon-reload

在使用systemctl启动前,需要将之前用./nginx启动的进程kill,否则会遇到这样的问题

[root@localhost system]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)

kill之前的进程

[root@localhost sbin]# ps -ef | grep nginx
root      26897      1  0 12:26 ?        00:00:00 nginx: master process ./nginx
nobody    26898  26897  0 12:26 ?        00:00:00 nginx: worker process
root      27724  22853  0 12:51 pts/1    00:00:00 grep --color=auto nginx

[root@localhost sbin]# kill 26897

systemctl管理Nginx

//启动和查看状态
systemctl start nginx
systemctl status nginx
//设置开机启动
systemctl enable nginx
systemctl is-enabled nginx
posted @ 2021-01-15 16:26  吴诺克  阅读(118)  评论(0编辑  收藏  举报
Copyright © 豆子林克 DOUZI.LINK  版权所有. 除特别申明外,本站原创内容版权遵循 CC-BY-NC-SA 协议规定