安装 Nginx
查看nginx配置
sudo nginx -t
安装 Nginx
在 Ubuntu / Debian 系统上安装 Nginx 可以按以下步骤来:
1. 更新系统软件包
sudo apt update sudo apt upgrade -y
这能确保你安装的是最新版本的 Nginx 及其依赖。
2. 安装 Nginx
sudo apt install nginx -y
安装完成后,Nginx 会自动启动。
3. 检查 Nginx 状态
systemctl status nginx
看到 active (running) 说明运行正常,按 q
退出状态查看。
4. 启动 / 停止 / 重启 Nginx
sudo systemctl start nginx # 启动
sudo systemctl stop nginx # 停止
sudo systemctl restart nginx # 重启
sudo systemctl reload nginx # 平滑加载配置
5. 设置开机自启
sudo systemctl enable nginx
6. 测试 Nginx
在浏览器访问你的服务器 IP,例如:
http://服务器IP
能看到 Welcome to nginx! 页面说明安装成功。