Nginx auto_index和auth_basic

1、nginx auto_index

nginx站点目录浏览功能,默认情况下为关闭

启用或禁用目录列表输出

开启这个功能的前提是站点目录下没有首页index.html

官方说明:http://nginx.org/en/docs/http/ngx_http_autoindex_module.html

语法Syntax:    autoindex on | off;

默认值Default:    autoindex off;

使用字段Context:    http(全局选项), server(单个网站选项), location(针对单个location)

使用范围:分享文件,搭建yum源等

1.1 在http下开启

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

autoindex on;

server {

省略其他内容

1.2 在location下开启

location / {

autoindex on;

省略其他内容

}

1.3 在server下开启

server {

listen 80;

server_name localhost;

autoindex on;

location

省略其他内容

开启目录浏览功能后,即可通过浏览器访问到站点并浏览目录,也可针对于某一目录

 

2、nginx auth_basic

    有时,我们需要为网站设置访问账号和密码权限,这样操作后,只有拥有账号密码的用户才能访问网站内容,这种使用账号密码才可以访问网站的功能主要应用在企业内部人员访问的地址上,例如:企业网站后台,MySQL客户端phpMyAdmin、企业内部的CRM、WIKI网站平台等。

官方说明:http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html

2.1 HTTP基本认证协议启用用户名和密码验证

语法Syntax:    auth_basic string(任意字符串) | off(关闭);

默认值Default:    auth_basic off;

使用字段Context:    http, server, location, limit_except

用法

修改配置文件,指定后面生成的密码文件保存路径(相对路径或绝对路径)

location / {

auth_basic "closed site";

auth_basic_user_file conf/htpasswd;

}

2.2 生成密码文件的方法

2.2.1 通过软件httpd-tools生成

安装生成验证密码文件的软件

yum install httpd-tools –y

查看安装httpd-tools后可用的二进制命令

rpm -ql httpd-tools

[root@Web01 conf]# rpm -ql httpd-tools

/usr/bin/ab

/usr/bin/htdbm

/usr/bin/htdigest

/usr/bin/htpasswd

省略输出

查看htpasswd用法

[root@Web01 conf]# htpasswd --help

Usage:

    htpasswd [-cmdpsD] passwordfile username

    htpasswd -b[cmdpsD] passwordfile username password

 

    htpasswd -n[mdps] username

    htpasswd -nb[mdps] username password

-c Create a new file.

-n Don't update file; display results on stdout.

-m Force MD5 encryption of the password.

-d Force CRYPT encryption of the password (default).

-p Do not encrypt the password (plaintext).

-s Force SHA encryption of the password.

-b Use the password from the command line rather than prompting for it.

-D Delete the specified user.

On Windows, NetWare and TPF systems the '-m' flag is used by default.

On all other systems, the '-p' flag will probably not work.

使用第二种方法非交互式一条命令生成密码文件

[root@Web01 conf]# htpasswd -bc /application/nginx/conf/htpasswd test 123456

Adding password for user test

[root@Web01 conf]# cat /application/nginx/conf/htpasswd

test:Hf2ctuRKkWaig

2.2.2 在线生成

利用网站在线生成

链接: http://tool.oschina.net/htpasswd

输入用户名和密码,选择适合当前web服务器的加密算法,然后把生成的结果手动添加到密码文件中

2.3 修改配置文件并生效

[root@Web01 conf]# vim nginx.conf

location / {

root html;

index index.html index.htm;

auth_basic "test";

auth_basic_user_file /application/nginx/conf/htpasswd;

    }

省略其他内容

[root@Web01 conf]# nginx -t        #检查语法

nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

[root@Web01 conf]# nginx -s reload    #平滑重启

清除浏览器缓存,访问站点测试,输入用户名密码后能进行访问

 

 

博主原创文章,转载请务必注明出处

Nginx auto_index和auth_basic的更多相关文章

  1. nginx配置指令auth_basic、auth_basic_user_file及相关知识

    参考链接 https://www.jianshu.com/p/1c0691c9ad3c auth_basic_user_file 所需要的密码,可以通过如下方法生成 1)安装htpasswd (yum ...

  2. Nginx 学习

    1.Nginx编译安装 nginx依赖于pcre库,需要先安装pcre(二进制包,跟正则表达式有关),pcre-devel(头文件) configure  --prefix=/usr/local/ng ...

  3. Nginx+Keepalived主主负载均衡服务器

    Nginx+keepalived主主负载均衡服务器测试实验环境: 主Nginx之一:192.168.11.27主Nginx之二:192.168.11.28Web服务器一:192.168.11.37We ...

  4. ELK+Redis 解析Nginx日志

    一.ELK简介 Elk是指logstash,elasticsearch,kibana三件套,我们一般使用它们做日志分析. ELK工作原理图: 简单来讲ELK具体的工作流程就是客户端的logstash ...

  5. centos7.3给squid搭建代理服务器添加认证nginx

    1先安装 nginx 这里是教程 点击查看 2 然后 使用命令 创建用户 htpasswd -c /etc/nginx/passwd.db baker 输入密码  提示添加完毕 3 查看加密后的用户和 ...

  6. Nginx主主负载均衡架构

    在和一些朋友交流Nginx+Keepalived技术时,我虽然已成功多次实Nginx+Keepaived项目方案,但这些都是用的单主Nginx在工作,从Nginx长期只是处于备份状态,所以我们想将二台 ...

  7. nginx索引目录配置

    为了简单共享文件,有些人使用svn,有些人使用ftp,但是更多得人使用索引(index)功能.apache得索引功能强大,并且也是最常见得,nginx得auto_index实现得目录索引偏少,而且功能 ...

  8. nginx虚拟主机配置实践

    1.配置基于域名的虚拟主机 [root@web01 html]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.defaul ...

  9. nginx典型官方模块解释

    模块名称 作用 语法 默认 配置位置 配置举例 结果验证 备注 1 --with-http_stub_status_module 监控Nginx的服务器连接状态 stub_status   serve ...

随机推荐

  1. 洛谷 P4171 [JSOI2010]满汉全席 解题报告

    P4171 [JSOI2010]满汉全席 题目描述 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的材料透过满族或是汉族的料理方式,呈现在數量繁多的菜色之中.由于菜色众多而繁杂,只有极少數博学多闻技艺高 ...

  2. 使用PowerShell登陆多台Windows,测试DCAgent方法

    目标: 需要1台PC用域账户远程登陆10台PC,每台登陆后的PC执行发送敏感数据的操作后,再logoff. 在DCAgent服务器上,查看这10个用户每次登陆时,DCAgent是否能获取到登陆信息(I ...

  3. VMware HA 特性

    关键特性1.自动检测服务器故障.VMware HA 自动监控物理服务器的可用性.VMware HA 可检测物理服务器故障,并且无需人工干预即可重新启动资源池中其他物理服务器上的新虚拟机.2.自动检测操 ...

  4. Android横竖屏切换解决方案

    Android横竖屏切换解决方案 首先在Mainifest.xml的Activity元素中加入android:configChanges="orientation|keyboardHidde ...

  5. AtCoder Grand Contest 018 A

    A - Getting Difference Time limit時間制限 : 2sec / Memory limitメモリ制限 : 256MB 配点 : 300 点 問題文 箱に N 個のボールが入 ...

  6. MongoDB中$redact操作符的使用

    介绍 redact <- redaction 修订/校验,意思是对文档内容进行过滤,选择一些过滤或保留的信息 . access level 存取等级 有三种: - $$DESCEND 返回当前等 ...

  7. Ubuntu 14.04 LTS+SublimeText3+中文输入

    文本编辑器,我习惯用Sublime Text,因为很好用啊,至于那些大神们说的Vim, Emacs,我目前还用不上:Vim偶尔会用到,gedit也会常用到,emacs几乎没用过,也不会: 一.安装: ...

  8. (2)oracle服务、建库

     一.oracle的服务 oracle 11g安装后服务一般是7到8个 1.Oracle ORCL VSS Writer Service Oracle卷映射拷贝写入服务(非必须启动) 2.Oracle ...

  9. Codeforces Round #445 B. Vlad and Cafes【时间轴】

    B. Vlad and Cafes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  10. Python_Tips[0] -> 关于 import

    关于 import 1 import import可用于导入一个Python的标准模块,包括.py文件或带有__init__.py的文件目录. 在Python中,import一个模块后,若再次impo ...