下载Nginx
wget http://nginx.org/download/nginx-1.15.5.tar.gz
解压
tar -xzvf nginx-1.15.5.tar.gz
生成Makefile,为下一步的编译做准备(可以根据需要删减参数)
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-pcre
安装出现的问题
hecking for C compiler ... not found
./configure: error: C compiler cc is not found
异常:缺失gcc
解决方案
yum -y install gcc gcc-c++ autoconf automake make
异常:缺失PCRE
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
解决
yum -y install pcre-devel
异常:缺失OpenSSL
error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option
解决:
yum -y install openssl openssl-devel
编译安装
make && make install
按指定配置文件启动Nginx
nginx -c /usr/local/nginx/conf/nginx.conf
停止操作是通过向nginx进程发送信号来进行的
步骤1:查询nginx主进程号ps -ef | grep nginx
在进程列表里 面找master进程,它的编号就是主进程号了。
步骤2:发送信号
从容停止Nginx:
kill -QUIT 主进程号
例如:kill -QUIT 16391
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
kill -9 主进程号
平滑重启
如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。
平滑重启命令:
kill -HUP 住进称号或进程号文件路径
或者使用
/usr/nginx/sbin/nginx -s reload
注意,修改了配置文件后最好先检查一下修改过的配置文件是否正确,
以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:
nginx -t -c /usr/nginx/conf/nginx.conf
或者
/usr/nginx/sbin/nginx -t
使用浏览器访问localhost,出现如下页面说明安装成功