ubuntu 安装nginx 并开启目录浏览功能

前端之家收集整理的这篇文章主要介绍了ubuntu 安装nginx 并开启目录浏览功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


首先 如果安装apache 应该卸载

sudo apt-get --purge remove apache2
sudo apt-get --purge remove apache2.2-common
sudo apt-get autoremove
删除掉的配置文件
sudo find  /etc -name "*apache*" -exec  rm -rf {} \;
sudo rm -rf /var/www

安装 Nginx

sudo apt-get update
sudo apt-get install Nginx

如果安装的Nginx 没有配置文件,且/etc/Nginx 没有则执行

删除,并查看与Nginx相关软件

sudo apt-get --purge remove Nginx 
sudo apt-get autoremove 
dpkg --get-selections|grep Nginx

删除Nginx-common 和Nginx-core

sudo apt-get --purge remove Nginx-common 
 sudo apt-get --purge remove Nginx-core
从新安装Nginx
sudo apt-get install Nginx

开始配置 Nginx 目录浏览功能

配置文件在 /etc/Nginx/下 Nginx.conf

目录浏览功能在server 下

查看Nginx.conf

cat /etc/Nginx/Nginx.conf

修改Nginx.conf

vim /etc/Nginx/Nginx.conf

如果 Nginx.conf 里 没有 server

则 在 http 下

添加 Vim 用法 百度

server{

    listen 80;

    server_name localhost;

    root /var/www/;

    index index.html;

    location /download{

        root /var/www/; # 指定目录路径
        autoindex on; #开启目录浏览

        autoindex_exact_size off; #以可读方式显示文件大小 单位kb,mb,gb

    }

}

然后 保存 重启 Nginx

/etc/init.d/Nginx restart

如果 重启 失败 fail 提示

* Restarting Nginx Nginx fail

则执行

sudo Nginx -t

查看错误位置,根据信息 修改

重启成功后

在 浏览器输入 你的 地址


然后成功


打开显示 404 或者403 请参考

http://blog.51yip.com/apachenginx/1512.html

https://zhangguodong.me/2017/01/22/nginx%E9%85%8D%E7%BD%AE%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95404/

原文链接:https://www.f2er.com/ubuntu/349844.html

猜你在找的Ubuntu相关文章