Nginx 搭建静态文件服务器

作者:张启昊
邮箱:1041520901@qq.com
更新日期:2023年08月07号


  1. Nginx安装

    yum install -y nginx
    

  1. 配置文件

    红帽Linux配置文件位置:/etc/nginx/nginx.conf

    docker配置文件位置:/etc/nginx/conf.d/default.conf

  2. 修改配置文件

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
        root        /files;                          ---- 静态文件目录
        error_log   /files/log/error.log;            ---- 错误日志保存位置
        access_log  /files/log/access.log;           ---- 访问日志保存位置
        charset utf-8;                               ---- 字符编码
    
        location / {
          autoindex on;                              ---- 开启目录索引
          autoindex_exact_size off;                  ---- 文件大小改为可读形式
          autoindex_format html;                     ---- 索引格式改为:html
          autoindex_localtime on;                    ---- 时间更改为服务器时间
        }
    }
    

  1. 保存文件并重启nginx服务

    systemctl restart nginx.service
    

  1. 效果图
    image-20230807185231689
posted @ 2023-08-07 19:00  张启昊  阅读(32)  评论(0)    收藏  举报