在 Debian 上安装 Nginx 通常有 两种方式:
下面先讲最常用的 apt 安装方式。
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
看到 active (running) 就说明成功了。
在浏览器访问服务器 IP:
http://你的服务器IP
看到 Welcome to nginx! 页面即安装成功。
sudo systemctl start nginx # 启动
sudo systemctl stop nginx # 停止
sudo systemctl restart nginx # 重启
sudo systemctl reload nginx # 重新加载配置
sudo nginx -t # 检查配置文件语法
如果开了 ufw:
sudo ufw allow 'Nginx Full'
/etc/nginx/nginx.conf/etc/nginx/sites-enabled//var/www/htmlDebian 自带源版本可能偏旧,可用 Nginx 官方源:
sudo apt install curl gnupg2 ca-certificates lsb-release -y
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt update
sudo apt install nginx -y
如果你是要 建网站 / 配置 HTTPS / 反向代理,可以继续问我,我可以给你具体配置示例。