部署流程
1.静态文件传输到指定Linux服务器,并解压
unzip yourFile.zip
2.用户名和密码生成
-- 请在username和userpassword出填写用户名和密码
printf "username:$(openssl passwd -crypt userpassword)\n" >> passwd
3.在Nginx的nginx.conf文件中进行配置
-- 静态文件目录结构,/home/your/superman/start.html
-- location 的目录配置
location ^~ /your/superman/ {
auth_basic "your are superman";
auth_basic_user_file passwd;
#autoindex on;
root /home;
index start.html;
}
遇到问题
1.中文乱码
解决方案:https://blog.youkuaiyun.com/gu_study/article/details/104778366
2.403Forbidden
403问题原因总结
目录存在问题
1.auth_basic_user_file 路径问题
auth_basic_user_file passwd;
# passwd在机器上的位置:/usr/local/nginx/conf/passwd
auth_basic_user_file conf/htpasswd;
# passwd在机器上的位置:/usr/local/nginx/conf/conf/passwd
auth_basic_user_file /tmp/htpasswd;
# passwd在机器上的位置:/tmp/passwd
2.location 路径和静态文件路径配置
选择root进行配置,而不是alias,对目录进行匹配,在location 后加 ^~