利用nginx搭建文件服务器

1.安装nginx

安装教程:https://www.cnblogs.com/sunny1009/p/11411673.html

2.配置nginx

配置server节点下的location部分和server下root指定访问目录

 server {
        listen       80;
        server_name  localhost;
        root /usr/local/static/;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            autoindex on;             #开启索引功能
            autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
            autoindex_localtime on;   # 显示本机时间而非 GMT 时间
            charset utf-8; # 避免中文乱码
            #root   html;
            #index  index.html index.htm;
        }
}

3.检查配置文件是否准确

./sbin/nginx -t

4.重新加载配置文件

./sbin/nginx -s reload

5.检验是否搭建成功

浏览器访问输入ip和对应端口号:http://192.168.31.170/

访问文件可以下载,图片可以浏览器直接显示

原文地址:https://www.cnblogs.com/sunny1009/p/11412316.html