1、下载包
wget http://nginx.org/download/nginx-1.25.2.tar.gz
2、解压缩
tar -zvxf nginx-1.25.2.tar.gz
3、安装前置
apt-get install gcc
apt-get install yum
apt-get install zlib1g zlib1g-dev
apt-get install openssl libssl-dev
apt-get install libpcre3 libpcre3-dev
4、安装
cd nginx-1.25.2
# 检查安装环境,是否符合
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 编译 安装
make && make install
# 运行
cd /usr/local/nginx/sbin
./nginx
5、开机自启动
vim /lib/systemd/system/nginx.service
输入
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6、设置开机启动
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx.conf
systemctl enable nginx.service
7、查看状态和其他操作
systemctl status nginx.service
ps aux | grep nginx
systemctl daemon-reload
# 启动
systemctl start nginx.service
# 结束
systemctl stop nginx.service
# 重启
systemctl restart nginx.service
#赋值命令
cp /usr/local/nginx/sbin/nginx /sbin/
#修改配置文件后重新加载
nginx -s reload