nginx配置密码访问

cooolr 于 2023-02-10 发布
sudo apt-get install apache2-utils
  1. 添加用户名密码
htpasswd -c /etc/nginx/.htpasswd username
  1. 配置nginx
server {
listen       80;
server_name  home.moosrtc.com;
location / {
    root   /codes/index;
    index  index.htm index.html;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
   }
}
  1. 重启nginx
nginx -t
nginx -s reload