Nginx adds access permissions to static files

    In order to facilitate reading information, such as technical articles, audio, and video, I Dockerset up NginxAfter friends and colleagues know more and more people, they feel that it is necessary to make some security restrictions.

  1. install software
apt install apache2-utils
  1. Create a directory
mkdir /etc/apache
  1. Create an account
htpasswd -c /etc/apache/htpasswd admin

Next follow the prompts to set a password

New password: 
Re-type new password: 
  1. modify Nginxconfiguration
server{
    
    
        listen 80;
        server_name *.*.*.*;
        root /usr/share/nginx/html;

        location /doc {
    
    
                auth_basic "账号登录";      # 开启认证
                auth_basic_user_file /etc/apache/htpasswd;    # 上面指定的密码文件
                alias /usr/share/nginx/html;
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
                charset utf-8,gbk;
        }
}
  1. Restart Nginxthe container
docker restart nginx

Guess you like

Origin blog.csdn.net/ChinaLiaoTian/article/details/125190827