配置nginx用户认证

1、安装nginx

apt-get update
apt-get install -y nginx

2、安装认证工具

apt-get install -y apache2-utils

3、配置认证账密

htpasswd -c /etc/nginx/.htpasswd your_username

4、配置nginx

vim /etc/nginx/nginx.conf

server {
    listen 80;
    server_name your_domain_name

    location / {
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri $uri/ /index.html;
    }
}

5、重启nginx

service nginx restart

 

posted @ 2023-11-08 17:48  awks  阅读(91)  评论(0)    收藏  举报