给nginx网站加密

  • A+
所属分类:运维教程

有时我们需要对网站的内容进行一些保护,例如内部网站、测试网站等等。当然,保护不代表不可以访问,只是有些人可访问,有些人不可以,那如何实现这种需求呢?我们可以通过nginx密码功能实现对网站加密。

首先我们看一下效果图:

给nginx网站加密

如果密码输入错误,就会出现这样的提示401 Authorization Required。

接下来我们开始讲如何配置。配置文件路径就不说了,每个人的路径都不相同,实在不知道的,可以使用如下命令查看地址:

find / -name birdteam.net.conf
#将birdteam.net换成你的域名

打开配置文件,将文件中添加注释下的两行内容,其中的password关键字可以自定义,并可写上路径:

server{
        listen 80;
        server_name birdteam.net www.birdteam.net;
#...
        location / {
#添加下面两行
        auth_basic "Restricted";
        auth_basic_user_file password;
#...
    }
#...
}

接下来我们需要创建一个密码文件来保存验证信息,我们取名为password,同文件中的password(如果取其它名,记得将配置文件中此名修改)将密码文件保存在与nginx.conf同目录中。

可使用如下的命令添加用户:

echo "username:password" >> password
#将username替换成用户名,password替换成密码

其中password的值需加密,可以通过https://birdteam.net/mima.php输出加密值。

最后重启nginx服务就行了。

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:36   其中:访客  36   博主  0

    • avatar pocket ring planner filofax

      I’m extremely impressed together with your writing abilities as smartly as
      together with the layout on your own weblog. Is the fact this a paid subject material
      or would you customize it yourself? In any event stay in the
      excellent quality writing, it is actually rare to appear a nice weblog similar to
      this one nowadays..

      my site :: pocket ring planner filofax

      • avatar grolyrtolemcs

        I truly appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again

        • avatar gold leaf strain

          Thanks for the sensible critique. Me and my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more from this post. I’m very glad to see such wonderful information being shared freely out there.

          • avatar MildredNNush

            What i don’t understood is the truth is how you will be
            not really considerably more well-appreciated than you might be now.
            You’re so intelligent. You understand thus considerably when it comes to this matter, made me i think imagine it from numerous
            varied angles. Its like men and women aren’t involved until it’s something to
            do with Lady gaga! Your own personal stuffs great. All the time cope with it up!

            Here is my web-site :: MildredNNush

            • avatar cbd oil that works 2020

              I just couldn’t go away your website prior to suggesting
              that I actually loved the usual info an individual provide
              for your visitors? Is going to be again incessantly to inspect
              new posts

              • avatar cbd oil that works 2020

                At this moment I am going to do my breakfast, afterward having my breakfast coming yet again to read further news.