開啟文件目錄 server { listen 80; #設置自己靜態目錄的訪問域名 server_name xxx.xxxx.com; #防止頁面中文亂碼一定要在utf-8前面加上gbk,順序很重要 charset utf-8; location / { #靜態目錄的絕對位置 root /file/statics; #Nginx默認是不允許列出整個目錄的,打開需要加上 autoindex on; #顯示出文件的確切大小,單位是bytes autoindex_exact_size on; #改為on后,顯示的文件時間為文件的服務器時間 autoindex_localtime on; } } 加密訪問 創建密碼文件和用戶密碼 將配置文件發在/etc/nginx/conf.d/ cd /etc/nginx/conf.d/ htpasswd -c .htpasswd quan #輸出2004密碼 在server區域加入 #設置密碼文件 auth_basic "提示語"; auth_basic_user_file /etc/nginx/conf.d/.htpasswd;