一、配置

再来创建一个新的虚拟主机

#cd /usr/local/nginx/conf/vhost

#vi test.com.conf

写入:

server

{

listen 80;

server_name test.com;

index index.html index.htm index.php;

root /data/nginx/test.com;

location /

{

auth_basic "Auth";

//打开认证

auth_basic_user_file /usr/local/nginx/conf/htpasswd;

//指定用户密码文件

}

}

#yum install -y httpd

//安装httpd,也可以使用之前编译安装的Apache2.4

下面创建和更新用于基本认证的用户认证密码文件

#htpasswd -c /usr/local/nginx/conf/htpasswd dongying

new password:

re-type new password:

Adding password for user dongying

# /usr/local/nginx/sbin/nginx -t

#/usr/local/nginx/sbin/nginx -s reload

#mkdir /data/nginx/test.com

#echo "test.com" > /data/nginx/test.com/index.html

二、测试

#curl -I -x127.0.0.1:80 test.com

状态码401

# curl -udongying:dongying -x127.0.0.1:80 test.com

[root@localhost vhost]# systemctl stop firewalld

[root@localhost vhost]# setenforce 0

关闭防火墙

编辑C:\Windows\System32\drivers\etc\hosts文件,添加映射

终端的IP test.com  ifconfig 查看

打开浏览器访问test.com

LNMP配置——Nginx配置 —— 用户认证的更多相关文章

  1. nginx 添加用户认证

    nginx 添加用户认证  nginx 配置文件添加: 配置代理添加用户认证:server {   listen       ;   server_name localhost;   location ...

  2. Nginx网站用户认证

    一.Nginx网站用户认证 用户认证:用户访问网页时需要输入一个用户名和密码才能打开网页. nginx的默认网页时安装目录下的html/index.html,配置文件在安装目录下的conf目录中的ng ...

  3. Linux服务器---配置apache支持用户认证

    Apache支持用户认证 为了服务器的安全,通常用户在请求访问某个文件夹的时候,Apache可以要求用户输入有效的用户名和登录密码 1.创建一个测试目录 [root@localhost cgi-bin ...

  4. YAPI工具配置LDAP统一用户认证

    背景:因为搭建了LDAP,因此希望将所有配置库或工具都使用LDAP进行统一用户认证,YAPI是其中一个. YAPI:使用docker-compose进行了安装,具体安装步骤自行百度. LDAP:使用d ...

  5. lnmp下 nginx 配置虚拟主机

    <一.参考> 这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设: IP地址: 202.55.1.100 域名1 example1.com 放在 /www/example ...

  6. 免费SSL-HTTS 申请与配置 NGINX配置

    Let's Encrypt是很火的一个免费SSL证书发行项目,自动化发行证书,证书有90天的有效期.适合个人使用或者临时使用,不用再忍受自签发证书不受浏览器信赖的提示.Let's Encrypt已经发 ...

  7. nginx访问控制用户认证两种方式

    一.用户认证1.首先需要用http来生成密码文件即安装apache :yum install -y httpd 生成密码文件:htpasswd -c /usr/local/nginx/conf/htp ...

  8. 三、Nginx设置用户认证

    要求:通过nginx服务端配置实现以下目标 访问web页面需要进行用户认证. 用户名为:tom,密码:123456 操作步骤, 更改配置文件 [root@client ~]# vim /usr/loc ...

  9. lnmp之Nginx配置https加密访问

    配置lnmp之Nginx网站支持https加密访问 注: 1. 这里拿购买的(pxsnx.pxjy.com)证书来做样例 证书文件共有三个---> (pxsnxg.pxjy.com_ca.crt ...

随机推荐

  1. Lightoj 1038 - Race to 1 Again【期望+dp】

    题目:戳这里 题意:一个数字n不断迭代地除以自身的因子得到1.求这个过程中操作除法次数的期望. 解题思路: 求概率基本都是从一个最基础的状态开始延伸推出公式,得出答案.因为每个数都有个共同的最终状态1 ...

  2. Linux command find All In One

    Linux command find All In One $ find -h # find: illegal option -- h # usage: # find [-H | -L | -P] [ ...

  3. React tutorial

    https://www.algolia.com Build Unique Search ExperiencesHosted Search API that delivers instant and r ...

  4. dark theme website

    dark theme website css var dark theme prefers-color-scheme https://developer.mozilla.org/en-US/docs/ ...

  5. HTTP/1.1 & HTTP/2 & webpack

    HTTP/1.1 & HTTP/2 & webpack Bundling your application is especially powerful for HTTP/1.1 cl ...

  6. js group objects in an array

    js group objects in an array js group objects in an array var groupBy = function(xs, key) { return x ...

  7. map & scale bug

    map & scale TW bug https://antv.alipay.com/zh-cn/g2/3.x/demo/map/drill-down.html import React, { ...

  8. moment.js & convert timestamps to date string in js

    moment.js & convert timestamps to date string in js https://momentjs.com/ moment().format('YYYY- ...

  9. apollo-server 返回模拟数据

    模式模拟GraphQL数据 const { ApolloServer, gql } = require('apollo-server'); const typeDefs = gql` type Que ...

  10. JULLIAN MURPHY:拥有良好的心态,运气福气便会自来

    JULLIAN MURPHY是星盟全球投资公司的基金预审经理,负责星盟投资项目预审,有着资深的基金管理经验,并且在区块链应用的兴起中投资了多个应用区块链技术的公司. JULLIAN MURPHY认为往 ...