安装环境: Centos7
创建目录及切换至目录
- # mkdir /usr/local/nginx
- # cd /usr/local/nginx/
下载 nginx 包, 访问 http://nginx.org/ 下载或 http://nginx.org/download 或使用命令下载
wget http://nginx.org/download/nginx-1.17.3.tar.gz
解压 nginx 包及移至解压目录
- # tar -zxvf nginx-1.17.3.tar.gz
- # cd nginx-1.17.3/
设置安装路径
# ./configure --prefix=/usr/local/nginx
若出现错误 [checking for C compiler ... not found] 需要执行如下命令
# yum -y install gcc gcc-c++ autoconf automake make
若出现下面的错误, 需要安装 openssl
- ./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 命令
# yum -y install openssl openssl-devel
编译 --make 是用来编译的, 它从 Makefile 中读取指令, 然后编译.
# make
安装 --make install 是用来安装的, 它也从 Makefile 中读取指令, 安装到指定的位置.
# make install
至此, nginx 已经安装成功, 接下来可以执行 nginx 命令来操作 nginx
命令
启动 -- # /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启 -- # nginx -s reload
重新打开日志文件 -- # nginx -s reopen
测试 nginx 配置文件是否正确 -- # nginx -t -c /usr/local/nginx/conf/nginx.conf
快速停止 -- # nginx -s stop
完整有序的停止 -- # nginx -s quit
也可以通过进程停止 nginx
查询 nginx 主进程号 -- # ps -ef | grep nginx
有序停止 -- # kill -QUIT 主进程号
快速停止 -- # kill -TERM 主进程号
强制停止 -- # pkill -9 nginx
平滑启动 -- # kill -HUP 主进程号
来源: https://www.cnblogs.com/GoCircle/p/11367695.html