nginx下载、安装和启动

linux版本:nginx下载源代码压缩包https://nginx.org/en/download.html,手动编译安装

上传到linux系统中

1、安装依赖环境

在编译前,确保系统已安装必要的工具和库:

ubuntu系统 

sudo apt update

sudo apt install -y build-essential libpcre3 libpcre3-dev zliblg-dev libssl-dev

 

2、解压,并进入源代码目录

tar -zxvf nginx-1.28.0.tar.gz

cd nginx-1.28.0

 

3、配置编译选项

运行configure脚本,指定安装位置 /usr/local/nginx

./configure --prefix=/usr/local/nginx

 

4、编译并安装

make

sudo make install

 

5、启动

cd /usr/local/nginx/sbin

sudo ./nginx

 

检查是否启动

ps aux|grep nginx

 

6、验证安装

http://服务器的ip,看到Welcome to nginx!页面即可成功

7、nginx其他常用命令

sudo ./nginx -s stop  (快速停止)

sudo ./nginx -s quit  优雅停止(处理完当前请求)

sudo ./nginx -s reload  重新加载配置

8、设置系统服务(可以选择不设置)

手动安装的 Nginx 需自行配置 systemd 服务:

创建服务文件

sudo vim /etc/systemd/system/nginx.service

 

写入以下内容

[Unit]
Description=The Nginx HTTP and reverse proxy server
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
PIDFile=/usr/local/nginx/logs/nginx.pid

[Install]
WantedBy=multi-user.target

 

启用服务

sudo systemctl daemon-reload
sudo systemctl start nginx
sudo systemctl enable nginx

 

posted @ 2025-05-19 20:03  李润  阅读(475)  评论(0)    收藏  举报