ubuntu安装配置nginx
1. 装包
若未升级系统,需先升级系统才能正常使用apt
#sudo apt update -y sudo apt install nginx -y
安装完成后,nginx会自启
sudo systemctl status nginx
若未自启动,根据提示执行
/lib/systemd/systemd-sysv-install enable nginx
防火墙放行
sudo ufw allow 'Nginx Full'
或
ufw allow proto tcp from 192.168.0.0/16 to any port 80
2. 配置
nginx配置文件在 /etc/nginx/nginx.conf
# cat conf.d/nginx-http-THE.conf server{ listen 80; server_name 192.168.192.168; location /THE { root /root/THE/; #指定目录所在路径 autoindex on; #开启目录浏览 autoindex_format html; #以html风格将目录展示在浏览器中 autoindex_exact_size off; #切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB autoindex_localtime on; #以服务器的文件时间作为显示的时间 charset utf-8,gbk; #展示中文文件名 } }
3. 启服务
systemctl restart nginx #启服务 curl http://192.168.192.168:80/THE #测试