1.更新下载源
sudo apt-get update
2.安装3个依赖pcre zlib openssl
sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install zlib1g-dev sudo apt-get install openssl libssl-dev 3.下载nginx
wget http://nginx.org/download/nginx-1.23.2.tar.gz
4.解压
tar -zxvf nginx-1.23.2.tar.gz 5. 进入解压后的nginx目录,安装配置nginx
./configure --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module ======================================================= 注意: 如果报错
checking for C compiler .. not found
./configure: error: C compiler cc is not found
执行以下命令:
sudo apt-get install build-essential ======================================================= 6.安装
sudo make && sudo make install 7.配置服务/lib/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=-/sbin/local/nginx/sbin/nginx -s stop
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
8.设置服务
systemctl daemon-reload
systemctl enable nginx.service 设置开机启动
systemctl start nginx.service
systemctl restart nginx.service
systemctl 管理 nginx 与 systemctl start nginx 卡住问题
要和nginx.conf中的pid保持一致,因此需要修改nginx.conf设置 pid /run/nginx.pid;