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

0次阅读

共计 420 个字符,预计需要花费 2 分钟才能阅读完成。

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

正文完
 0