首页 > 系统服务 > 详细

阿里云centos7[linux]安装nginx

时间:2021-01-10 15:22:42      阅读:20      评论:0      收藏:0      [点我收藏+]
标题 说明
服务器版本 Centos7 x64
nginx版本 1.19.6
作者 walton

一、准备

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

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

或者

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

Q: 如何获取下载版本?

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

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

cd /nginx-1.19.6

二、安装

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

出现如下错误

技术分享图片

./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,执行以下命令

[root@fanzyx nginx-1.19.6]# yum -y install openssl openssl-devel

再次执行命令
[root@fanzyx nginx-1.19.6]# ./configure --prefix=/usr/local/nginx

技术分享图片

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

[root@fanzyx nginx-1.19.6]# make

编译成功,如图所示、

技术分享图片

  1. 安装文件

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

[root@fanzyx nginx-1.19.6]# make install

三、相关命令

  1. 启动

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

[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  1. 停止
方法一:
[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -s stop
方法二:
查询nginx进程
ps -ef | grep nginx
[root@fanzyx 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

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

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

技术分享图片

  1. 重启
安装路径 -s reload

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

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

如下所示配置成功
[root@fanzyx 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
[root@fanzyx nginx-1.19.6]# 


阿里云centos7[linux]安装nginx

原文:https://www.cnblogs.com/fanzyx/p/14257982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!