一、安装 Nginx
ubuntu源仓库直接安装
sudo apt update
sudo apt install nginx
验证安装
sudo systemctl status nginx
防火墙(未使用)
datalab@datalabvm12:/etc/nginx$ sudo ufw allow 'Nginx Full'
Skipping adding existing rule
Skipping adding existing rule (v6)
datalab@datalabvm12:/etc/nginx$ sudo ufw status
Status: inactive
查看端口被占用
sudo netstat -tln | grep 80
sudo lsof -i :80
kill -9 <pid> #按进程id杀死进程
二、配置nginx
datalab@datalabvm12:~$ cd /
datalab@datalabvm12:/$ cd etc/nginx
datalab@datalabvm12:/etc/nginx/conf.d$ sudo vim nginx.conf
datalab@datalabvm12:/etc/nginx/conf.d$ cat nginx.conf
server{
listen 8080;
server_name 10.80.xx.xx;
location / {
root /var/www/html;
index index.html;#cp index.nginx-debian.html index.html
}
}
检查
sudo nginx -t nginx.conf #配置文件是否有问题
sudo systemctl restart nginx #重启nginx
curl http://10.80.xx.xx:8080 #服务器上尝试访问
在浏览器中打开