nginx配置文件下载并且设置用户认证

1.nginx配置文件

server {
        listen       80;
        location /down {
           auth_basic "User Authentication";
           auth_basic_user_file /etc/nginx/conf.d/user/file-download-user.db;
           alias /var/www/pub;
           sendfile on;
           autoindex on;
           autoindex_exact_size on;
           autoindex_localtime on;
           charset utf-8,gbk;

2.安装加密命令并且配置

yum -y install httpd-tools
mkdir /etc/nginx/conf.d/user
htpasswd -c /etc/nginx/conf.d/user/file-download-user.db test #输入密码即可
nginx -s reload

访问http://xxxx:80/down 即可跳出输入密码页面,登录后即可查看到/var/www/pub下的文件。

posted @ 2024-06-13 16:54  物是人非a  阅读(137)  评论(0)    收藏  举报