鍍金池/ 問答/Linux  HTML/ nginx配置指定路徑為下載目錄?

nginx配置指定路徑為下載目錄?

server {
    listen       80;        #端口
    server_name  localhost;   #服務(wù)名
    index  index.html;
    charset utf-8; # 避免中文亂碼
    root    /data/static;  #顯示的根索引目錄,注意這里要改成你自己的,目錄要存在

    location / {
        autoindex on;             #開啟索引功能
        autoindex_exact_size off; # 關(guān)閉計(jì)算文件確切大?。▎挝籦ytes),只顯示大概大小(單位kb、mb、gb)
        autoindex_localtime on;   # 顯示本機(jī)時(shí)間而非 GMT 時(shí)間
    }
}

我這樣通過nginx 設(shè)置了下載服務(wù)器,打開我的服務(wù)器的時(shí)候 118.118.118.118,這樣就會(huì)顯示我的一個(gè)/data/static 目錄里面的文件清單。

現(xiàn)在我不想讓118.118.118.118 改成118.118.118.118/download
我嘗試了下面這些操作

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

都不能成功,所以我想請(qǐng)問下應(yīng)該怎么設(shè)置呢?

回答
編輯回答
墻頭草
location /download {
    alias /data/static;
    autoindex on;             #開啟索引功能
    autoindex_exact_size off; # 關(guān)閉計(jì)算文件確切大?。▎挝籦ytes),只顯示大概大?。▎挝籯b、mb、gb)
    autoindex_localtime on;   # 顯示本機(jī)時(shí)間而非 GMT 時(shí)間
}
2018年1月4日 13:56