首页 > Web开发 > 详细

nginx配置网页密码

时间:2020-10-29 12:43:00      阅读:34      评论:0      收藏:0      [点我收藏+]

环境:

nginx 1.16
httpd Apache/2.4.6

 

 

 

yum安装方式:(yum没有此软件时,需要配置yum源)

yum install nginx -y   
yum install httpd -y

启动nginx  、httpd

systemctl start nginx
systemctl  start httpd

创建密文

[root@243-ceshi download]# htpasswd -cb /dwz/htpasswd kaifa2  vrgv25.      
Adding password for user kaifa2 [root@243-ceshi download]# cat /dwz/htpasswd kaifa2:$apr1$UJrSJ10s$asQLF/ImBymWnB1zk5U6S0

注:/dwz目录需要存在,要不会报错

nginx配置文件:

 


[root@243-ceshi download]#vim /etc/nginx/nginx.conf.d/download.conf
server {
        listen       30000;                                          #端口号自定义
        root         /usr/share/nginx/html;                           
        auth_basic "This is input password";                         #网页输入密码提示语
        auth_basic_user_file /dwz/htpasswd;                          #密文存放位置
        # Load configuration files for the default server block.

location /download {                                                  #下面是自定义下载引导位置,当访问ip:30000/download后会转到服务器的/download/目录下,提供下载
    charset utf-8;                                                    #支持中文
    alias /download/;                                                 #转的下载目录
    index index.html;
    autoindex on;
    autoindex_exact_size off;
}
}

注:download.conf配置文件是自定义创建的,并被nginx管理

重新启动nginx

systemctl restart nginx

打开网址:

 

技术分享图片

 

 

完成

 

nginx配置网页密码

原文:https://www.cnblogs.com/dongweizhen/p/13895814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!