目录
下载安装包
上传至linux对应文件夹
先上传至/usr/local,cd进压缩包所在的对应的目录,在这里解压,运行命令
cd /usr/local/ tar -zxvf nginx-1.20.1.tar.gz #文件名根据你自己的压缩包文件名来
make
将解压好的文件夹重命名为nginx,进入,依次执行
cd /usr/local/nginx ./configure make make install mkdir logs
如果make执行报错make: *** No rule to make target 'build', needed by 'default'. Stop.
则重新解压并在之前加两步。
yum update yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel cd /usr/local/nginx ./configure make make install mkdir logs
安装服务
进入/etc/systemd/system,找到nginx.service
1.如果没有找到对应文件,则直接启动
cd usr/local/nginx/sbin ./nginx
2.如果找到了,进行修改
内容在这,注意内容中包含路径,如果你的路径不跟我完全一致自行修改
[UNIT] Deion=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
运行启动
systemctl enable nginx
失败也没关系,重启一下远程服务器试试
加环境变量
去linux主目录在profile下面加一行就行,记得地址改自己的
export PATH=$PATH:/usr/local/nginx/sbin
去命令行执行让它生效
source /etc/profile
nginx常用命令
关闭
nginx -s stop
重启
nginx -s reload
配置文件
nginx -c 路径/nginx.conf