目录
一、下载网络下载压缩包
[root@localhost ~]# wget -c https://repo.huaweicloud.com/nginx/nginx-1.20.0.tar.gz
解压到指定位置
[root@localhost ~]# tar xf nginx-1.20.0.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/nginx-1.20.0/
二、创建用户
创建用户
useradd -r -s /sbin/nologin -M nginx
三、安装一些依赖包
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-threads --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --with-stream --with-pcre
安装gcc gcc-c++ make
yum install gcc gcc-c++ make -y
安装pcre-devel
yum install pcre-devel -y
安装openssl
yum install openssl-devel -y
yum install perl-devel -y
yum install perl-ExtUtils-Embed -y
如下就是该有的包都有了
[root@localhost nginx-1.20.0]# ./configure
下一步
make
make install
tree /usr/local/nginx/
切换到此位置 cd /usr/local/nginx/sbin
创建如下软连接
[root@localhost sbin]# ln -sv /usr/local/nginx/sbin/nginx /usr/sbin/nginx
#查看nginx版本 nginx -v
四、编写脚本
一定要写对路径不然可能启不起来
[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
此时就可以启动nginx了
systemctl start nginx