nginx配置指定路径为下载目录?

server {
    listen       80;        #端口
    server_name  localhost;   #服务名
    index  index.html;
    charset utf-8; # 避免中文乱码
    root    /data/static;  #显示的根索引目录,注意这里要改成你自己的,目录要存在

    location / {
        autoindex on;             #开启索引功能
        autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
        autoindex_localtime on;   # 显示本机时间而非 GMT 时间
    }
}

我这样通过nginx 设置了下载服务器,打开我的服务器的时候 118.118.118.118,这样就会显示我的一个/data/static 目录里面的文件清单。

现在我不想让118.118.118.118 改成118.118.118.118/download
我尝试了下面这些操作

    # ...
    location /download {
         #...
    }
    # ...
    location ~/download {
         #...
    }
    # ...
    location / {
        root download;
         #...
    }

都不能成功,所以我想请问下应该怎么设置呢?

阅读 10.2k
1 个回答
location /download {
    alias /data/static;
    autoindex on;             #开启索引功能
    autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
    autoindex_localtime on;   # 显示本机时间而非 GMT 时间
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题