编译安装nginx服务
关闭防火墙安装依赖包
systemctl stop firewalld
setenforce 0
yum install -y pcre-devel zlib-devel gcc gcc-c++ make
创建运行用户和组,便于管理
nginx服务程序默认以nobody身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限。
[root@root ~]# useradd -M -s /sbin/nologin nginx
解压软件包,编译安装nginx·
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \ #指定nginx的安装路径
--user=nginx \ #指定用户名
--group=nginx \ #指定组名
--with-http_stub_status_module #启用 http_stub_status_module 模块以支持状态统计操作 VTS
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #让系统识别nginx的操作命令
检查、启动、重启、停止nginx服务
[root@localhost nginx-1.12.2]# 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@localhost nginx-1.12.2]# nginx
[root@localhost nginx-1.12.2]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 4452 root 6u IPv4 30635 0t0 TCP *:http (LISTEN)
nginx 4453 nginx 6u IPv4 30635 0t0 TCP *:http (LISTEN)
[root@localhost nginx-1.12.2]# kill -3 4452
[root@localhost nginx-1.12.2]# nginx
[root@localhost nginx-1.12.2]# cat /usr/local/nginx/logs/nginx.pid
4464
[root@localhost nginx-1.12.2]# kill -1 4464
[root@localhost nginx-1.12.2]# kill -s HUP 4464
升级nginx服务
[root@localhost opt]# tar xf nginx-1.22.0.tar.gz
[root@localhost nginx-1.22.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old 备份
cp objs/nginx /usr/local/nginx/sbin/nginx
重启服务 并且
nginx -V #查看版本