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/



posted @ 2018-03-14 10:45  Sizaif  阅读(1147)  评论(0编辑  收藏  举报