1、安装了必要的开发工具和库文件
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
2、下载Nginx源码
cd /home/kylin
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.26.2.tar.gz
cd nginx-1.26.2
3、配置Nginx
./configure --prefix=/home/kylin/nginx \
--with-http_ssl_module
4、编译并安装
sudo make
sudo make install
5、修改用户
sudo vi /home/kylin/nginx/conf/nginx.conf
user kylin; #修改用户
6、启动服务
sudo /home/kylin/nginx/sbin/nginx
7、监控服务
ps aux | grep nginx
netstat -tuln | grep :80
8、设置开机启动
sudo vi /etc/systemd/system/nginx.service
内容如下
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target[Service]
Type=forking
PIDFile=/home/kylin/nginx/run/nginx.pid
ExecStartPre=/home/kylin/nginx/sbin/nginx -t -c /home/kylin/nginx/conf/nginx.conf
ExecStart=/home/kylin/nginx/sbin/nginx
ExecReload=/home/kylin/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
更新systemd并启动服务
sudo systemctl daemon-reload
sudo systemctl enable nginx
sudo systemctl start nginx