给nginx配置密码

一、安装nginx
sudo apt-get -y install nginx

二、配置密码
server {
    listen 80;
    server_name www.hello.com;
    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/htpasswd.users;

    location / {
        proxy_pass http://localhost:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

三、配置密码
sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/htpasswd.users nginx_admin
sudo service nginx restart

发表评论