安装
使用APT命令从Ubuntu的默认存储库中安装NGINX
sudo apt update
sudo apt install nginx
接下来,您需要调整防火墙
sudo ufw app list
然后它将显示可用的应用程序
- nginx Full
- nginx http
- Openssh
- nginx https 建议启用最严格的轮廓。由于未配置SSL,因此暂时允许非SSL流量
sudo ufw allow 'Nginx HTTP'
现在验证状态
sudo ufw status
接下来,我们需要验证安装状态
systemctl status nginx
使用服务器的IP地址访问默认的NGINX着陆页。这是一些获取服务器IP地址的方法
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
获取服务器公共IP地址的另一种方法是
curl -4 icanhazip.com
当您拥有服务器的IP地址时,将其输入到浏览器的地址栏中:
http://your_server_ip
就是这样。 NGINX已成功安装。
一些有用的命令
停止Web服务器
sudo systemctl stop nginx
启动Web服务器
sudo systemctl start nginx
停止然后启动服务器
sudo systemctl restart nginx
重新加载Web服务器
sudo systemctl reload nginx
禁用和启用nginx
sudo systemctl disable nginx
要重新启用服务以在启动时启动,您可以输入:
sudo systemctl enable nginx