关于nginx:Ubuntu-下-使用nginx设置用户名密码访问

1.下载工具

sudo apt-get install apache2-utils
  1. 增加用户名明码
htpasswd -c /etc/nginx/.htpasswd username

输出明码,提醒如下:

New password:
Re-type new password:
Adding password for user exampleuser

htpaswd的.htpasswd文件格式如下:
login:password
留神:htpasswd须要对nginx运行用户可拜访

增加配置到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;
   }
  }

重启

sudo service nginx restart

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理