阿里云centos7[linux]安装nginx

标题 说明
服务器版本 Centos7 x64
nginx版本 1.19.6
作者 walton

一、准备

  1. 创建安装包目录并进入
mkdir /usr/dev/nginx

cd /usr/dev/nginx
  1. 下载安装包
wget //nginx.org/download/nginx-1.19.6.tar.gz

或者

在 //nginx.org/download/ 直接下载对应版本安装包上传到服务器文件夹内

Q: 如何获取下载版本?

A: 在此网站中(//nginx.org/download/)获取版本,然后修改wget命令后的版本号

  1. 解压安装包并进入
tar -zxvf nginx-1.19.6.tar.gz

cd /nginx-1.19.6

二、安装

  1. 设置安装路径(默认路径:/usr/local/nginx)
[[email protected] nginx-1.19.6]#  ./configure --prefix=/usr/local/nginx

出现如下错误

1-1

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

需要安装openssl,执行以下命令

[[email protected] nginx-1.19.6]# yum -y install openssl openssl-devel

再次执行命令
[[email protected] nginx-1.19.6]# ./configure --prefix=/usr/local/nginx

1-2

  1. 编译nginx
当前目录下执行make命令,该命令是将源文件编译为可执行文件

[[email protected] nginx-1.19.6]# make

编译成功,如图所示、

1-3

  1. 安装文件

将编译后的文件复制到设置的安装目录

[[email protected] nginx-1.19.6]# make install

三、相关命令

  1. 启动

为nginx指定配置文件路径并启动

[[email protected] nginx-1.19.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  1. 停止
方法一:
[[email protected] nginx-1.19.6]# /usr/local/nginx/sbin/nginx -s stop
方法二:
查询nginx进程
ps -ef | grep nginx
[[email protected] nginx-1.19.6]# ps -ef | grep nginx
root     15038     1  0 11:44 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   15039 15038  0 11:44 ?        00:00:00 nginx: worker process
root     15084  9881  0 11:45 pts/0    00:00:00 grep --color=auto nginx

在进程列表中带master的进程就是主进程

kill -QUIT 主进程号
eg: kill -QUIT 15038

再次执行查询命令发现主进程已消失

[[email protected] nginx-1.19.6]# kill -QUIT 15038
[[email protected] nginx-1.19.6]# ps -ef | grep nginx
root     15271  9881  0 11:50 pts/0    00:00:00 grep --color=auto nginx
[[email protected] nginx-1.19.6]# 

1-4

  1. 重启
安装路径 -s reload

/usr/local/nginx/sbin/nginx -s reload
  1. 查看配置是否正确
安装路径 -t

/usr/local/nginx/sbin/nginx -t

如下所示配置成功
[[email protected] nginx-1.19.6]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] nginx-1.19.6]# 


Tags: