Select Page

Nginx 配置访问网站密码方法

Nginx 配置访问网站密码方法

有些时候出于某种原因,比如我们放了一些测试站点并不希望被任何人随意访问,那么就很有必要利用服务器配置和htpasswd文件来实现访问的密码验证。

使用root用户登录,运行以下命令:

# 安装httpd
yum install httpd

在网站的conf文件中加入

  location  /
{
  auth_basic "Hit Me";
  auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}

然后输入如下代码,按提示创建用户名与密码

htpasswd -c /usr/local/nginx/conf/htpasswd 你的用户名

重启Nginx后就完成了

lnmp nginx restart

使用方法

About The Author

Jackie Sung

Jackie Sung, also known by his nick-name KK, always strives for the best and learn from the best. Influenced by the age of Internet, for the last few years, in his spare time, he's been working and living as a Freelance Web Engineer/ Web Developer & Designer/ Amateur Photographer/ Husky Lover. The work he provides is of highest quality, fully-customized responsive, and tested in a wide range of devices, which typically covers both front-end (HTML5/ CSS3/ JavaScript) and back-end (WordPress as the CMS) responsibilities.

Leave a reply

电子邮件地址不会被公开。 必填项已用*标注

6 + 17 =

关于本站

主要用于记录和分享我所折腾过的东西
因为业务关系,本站采用双语
我是菜鸡 各位大佬多包含 别DDCC我 谢谢
工作联系 hello#jackiesung.com 将#换成@

订阅本站

Pin It on Pinterest

Share This