Ubuntu22.04安装nginx
1.安装nginx
-
首先,更新你的包索引:
sudo apt update
-
安装必要的软件包以允许apt通过HTTPS使用仓库:
sudo apt install ca-certificates curl gnupg lsb-release
-
添加Nginx官方的GPG密钥:
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
-
为Nginx设置官方的APT仓库:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
-
再次更新包索引:
sudo apt update
-
安装Nginx:
sudo apt install nginx
-
确认安装并启动Nginx服务:
sudo systemctl start nginx
sudo systemctl enable nginx
-
验证Nginx是否已经成功运行:
systemctl status nginx
或者,在浏览器中输入你的服务器IP地址,如果看到Nginx的欢迎页面,说明Nginx已经成功安装并运行。
curl IP地址 # 能看见返回的前端代码就是正确的